Open nightswimmer opened 11 years ago
I think need to be put in try catch so don't trigger the error
try
{
localWs.close();
}
catch(err){
//err.message
}
even better check if the readyState is not 3 - CLOSED
if( ! localWs.readyState === 3 )
{
localWs.close();
}
@daniel3d, better use the defined constant for this cases:
localWs.readyState === WebSocket.CLOSED
Did this solve your problem @nightswimmer ?
I used the try/catch and it seemed to work. But now in some situations it doesn't seem to reconnect, don't know if it could be because of that.
I was having the same problem and doing this fixed it:
if (!localWs.readyState === WebSocket.CLOSED)
localWs.close();
@lukevers, you have a logical error.
In expression like "!a === b" variable "a" turns to boolean, when in expression "a !== b" all good.
@myadzel haha, thanks for point that out! I saw @daniel3d's response and then your response to his to use Websocket.CLOSED
instead of 3
and I just threw it all together without thinking about it.
Hello all dear. I am pretty new in WebSocket. I have this problem too. This is my javascript to test connecting to server:
$(function () {
// Correctly decide between ws:// and wss://
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
var ws_path = ws_scheme + '://' + window.location.host + "/chat/stream/";
console.log("Connecting to " + ws_path);
var socket = new ReconnectingWebSocket(ws_path);
// Helpful debugging
socket.onopen = function () {
console.log("Connected to chat socket");
};
socket.onclose = function () {
console.log("Disconnected from chat socket");
}
});
but this is the result that printed in Chrome developer console:
WebSocket connection to 'ws://127.0.0.1:8000/chat/stream/' failed: WebSocket is closed before the connection is established
please help! thanks a lot.
I have the same problem as kasaiee when opening a wss url using the minified library, which I downloaded from this project just 2 months ago.
The connection later becomes usable, so I'd like to avoid the false alarms that this triggers in our reporting system.
Update: This problem occurs every time I use recent Chrome on Win10 to make an initial wss connection, but when I try Safari/iOS 13.1 it doesn't occur.
I submitted this PR: https://github.com/joewalnes/reconnecting-websocket/pull/112/commits/63361538d6be9ebffdb255b2140cb60fec21b2f9
Hello. I get this error "WebSocket is closed before the connection is established." when I try to connect and the server is inacessible. The error seems to come from the line: localWs.close(); when localWs.readyState has the value 0
Is this error normal/unavoidable?