Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
167
rated 0 times [  169] [ 2]  / answers: 1 / hits: 19392  / 10 Years ago, tue, april 29, 2014, 12:00:00
connection = new WebSocket(ws://localhost:1050/join?username=test)

connection.onopen = function(){
alert('Connection open!');
}


connection.onmessage = function(e){
var server_message = e.data;
alert(server_message);
}

connection.onclose = function() {
alert(websocket closing)
}


The connection to the server is established and an alert is displayed for Connection open! However immediately afterwards the connection closes. The server does not call close and there seem to be no other errors in the console. This is happening in both chrome and firefox.



I looked at a bunch of different similar examples on the web but to no avail.


More From » websocket

 Answers
26

Fixed it!



All I had to do was block the handler from returning before the websocket connection closes


[#71260] Saturday, April 26, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
everett

Total Points: 317
Total Questions: 112
Total Answers: 109

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
;