Closing Websocket Correctly (Html5, JavaScript)

Handling connection loss with websockets

This was the solution I ended up doing which seems to work fine for the time being, it's entirely specific to my project's setup & relies on criteria being in place that wasn't originally mentioned in my question, but it might be useful for someone else if they happen to be doing the same thing.

The connection to the websocket server occurs within a Firefox addon, and by default Firefox's TCP setup has a 10 minute timeout. You can see additional details with about:config and searching for TCP.

Firefox addons can access these parameters

var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);

and also change these parameters by specifying the branch & preference along with the new value

prefs.getBranch("network.http.tcp_keepalive.").setIntPref('long_lived_idle_time', 10);

So now, any computer with the addon installed have a 10 second timeout for TCP connections. If the connection is lost, the onclose event is triggered which displays an alert and also attempts to re-establish connection

websocket_conn.onclose = function (e) {
document.getElementById('websocket_no_connection').style.display = 'block';
setTimeout(my_extension.setup_websockets, 10000);
};

Websocket closing connection after it's opened

Problem resolved. The cause of it was in the constructor. It was incorrect. I just removed it and now it works.

jetty 9, websockets and closing websocket connection on server side

There were a few close and disconnect detection bugs in Jetty 9.0.0

  • 406449 - Session's disconnect not detected
  • 404991 - WebSocketCloseTest fails spuriously

Both of those were recently fixed and delivered in Jetty 9.0.3.v20130506 please give that version a try.



Related Topics



Leave a reply



Submit