Here is a JavaScript sample of a WebSocket that will try to reconnect every second if the connection is lost to the server. This is completely transparent to the end-user.
function WS() { var _self = this; this.start = function() { var ws; ws = new WebSocket("ws://example.com/"); ws.onmessage = function(e) { // Do something }; ws.onclose = function(e) { clearTimeout(_self.refresh); setTimeout(_self.start, 1000); } } _self.start(); } new WS();
