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
Write/Add Data in JSON File Using Node.Js
Cryptic "Script Error." Reported in JavaScript in Chrome and Firefox
Ternary Operators in JavaScript Without an "Else"
How to Open a Url in a New Tab Using JavaScript or Jquery
JavaScript Seconds to Minutes and Seconds
Send Post Data on Redirect with JavaScript/Jquery
How to Remove a Buggy Service Worker, or Implement a "Kill Switch"
How to Get the Anchor from the Url Using Jquery
How to Find the Array Index with a Value
Easy to Understand Definition of "Asynchronous Event"
How to Limit Panning in Google Maps API V3
Correct Use of Arrow Functions in React
Why Would Multiple Simultaneous Ajax Calls to the Same ASP.NET MVC Action Cause the Browser to Block