You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
michaelSaunders edited this page Mar 11, 2018
·
6 revisions
Websocket notes
Connecting to the server client side
$(function(){// Correctly decide between ws:// and wss://varws_scheme=window.location.protocol=="https:" ? "wss" : "ws";//set some path "foo/bar" to sever routervarws_path=ws_scheme+'://'+window.location.host+"/foo/bar";console.log("Connecting to "+ws_path);//builds connectionvarsocket=newReconnectingWebSocket(ws_path);socket.onmessage=function(message){vardata=JSON.parse(message.data);if(data.error){alert(data.error);return;}}//Heartbeat function sends a ping every 10 seconds to serversetInterval(function(){socket.send(JSON.stringify("heartbeat"));},10000);