import two JS before the page is loaded;
varsocketstatus=false; varT2;//re-connect organizationfunction Tanchuang () {Offline.check (); //to False when executing if(!socketstatus) {Alertsvc.layalerterr ("The current network is poor, please try again later! "); if(Offline.state = = =' up'&& websocket.reconnectattempts>websocket.maxreconnectinterval) {window.location.reload (); } } } //Websock Connection Eventsfunction Websocketconnect (add) {if(Add = =undefined) {Add=CIP; } if('WebSocket' inchwindow) {WebSocket=NewReconnectingwebsocket (add); } Else if('Mozwebsocket' inchwindow) {WebSocket=NewMozwebsocket (add); } Else{websocket=Newsockjs (add); } //callback method for successful connection establishmentWebsocket.onopen =function () {//re-connect organizationsocketstatus=true; T2=setinterval (Tanchuang, the); }; //callback method for receiving messageWebsocket.onmessage = function (Event) { }; //the callback method where the connection error occurred \Websocket.onerror =function () {Socketstatus=false; Console.log ("WebSocket Connection Error"); }; //callback method for connection shutdown 2017-08-15Websocket.onclose =function () {Socketstatus=false; Console.log ("WebSocket Connection off"); }; //listen to the window Shutdown event, when the window is closed, actively to close the WebSocket connection, to prevent the connection has not been disconnected and close the window, the server side will throw an exception. Window.onbeforeunload =function () {if(Event. ClientX > Document.body.clientWidth &&Event. ClientY <0||Event. Altkey) {Closewebsocket (); } };
<script src= "Lib/offline.js" ></script>
<script src= "Lib/rewebsocket.js" ></script>
2017-08-15 12:11:29
Websock re-connect agency abridged edition