Websock re-connect agency abridged edition

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.