WebSocket is a protocol providing full-duplex communications channels over a single TCP connection. It is a next-generation bidirectional communication technology for web applications which operates over a single socket and is exposed via a JavaScript interface in HTML 5 compliant browsers.
Since it is completely depends on the TCP connection, Any network disturbance or network latency may lead to disturbance of the websockets but in this case onclose callback method of websocket will not be get called. This error leads to a data discrepancy. In this scenario readyState attribute of web socket also will not give you the correct value.
We can use below code to find out web socket is alive or not,what is does is it will try to send the some ping message to server.We will get error in case of websocket is not alive
var webSocket = new WebSocket(url, [protocal] ); try{ webSocket('test message'); }catch(err) { // your logic here in case of websocket dead }
0 Comments
Post a Comment