Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "WebSocket is closed before the connection is established" mean?

I'm using JavaScript and the Union platform How would I go about diagnosing this problem? Many thanks.

like image 204
user1144112 Avatar asked Sep 19 '12 02:09

user1144112


People also ask

Why WebSocket is closed before the connection is established?

In this code what it means is that ws. close() was called (by user code) before the connection was even given a chance to be established. So, the cause of this error is if code attempts to close the WebSocket connection before it's had a chance to actually connect.

Why are WebSockets closed?

Parameters. An integer WebSocket connection close code value indicating a reason for closure: If unspecified, a close code for the connection is automatically set: to 1000 for a normal closure, or otherwise to another standard value in the range 1001 - 1015 that indicates the actual reason the connection was closed.

How do I reopen a WebSocket connection?

To open a websocket connection, we need to create new WebSocket using the special protocol ws in the url: let socket = new WebSocket("ws://javascript.info"); There's also encrypted wss:// protocol. It's like HTTPS for websockets.


1 Answers

If you go to http://jsbin.com/ekusep/6/edit and view the JavaScript console you'll see the 'WebSocket is closed before the connection is established' logged. I've tested this in Chrome.

In this code what it means is that ws.close() was called (by user code) before the connection was even given a chance to be established.

So, the cause of this error is if code attempts to close the WebSocket connection before it's had a chance to actually connect.

like image 137
leggetter Avatar answered Oct 14 '22 06:10

leggetter