Skip to content

Instantly share code, notes, and snippets.

@linusthe3rd
Created March 2, 2014 17:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linusthe3rd/9310390 to your computer and use it in GitHub Desktop.
Save linusthe3rd/9310390 to your computer and use it in GitHub Desktop.
WebSocket Reconnection with Basic Polling
// Polling example to reconnect a WebSocket connection. I recommend NOT using this in your app.
function createWebSocket () {
var connection = new WebSocket();
connection.onclose = function () {
setTimeout(function () {
// Connection has closed so try to reconnect every 10 seconds.
createWebSocket();
}, 10*1000);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment