Two properties of WebSocket: ReadyState and Bufferedamount.
depending on the ReadyState property, you can determine the connection state of the WebSocket, and the value of this property can be the following:0: corresponding constant connecting (numeric value 0),A connection connection is being established and is not yet complete. The connection have not yet been established.1: Corresponding constant open (numeric value 1),The connection is successfully established and can be communicated. The WebSocket connection is established and communication are possible. 2: Corresponding constant closing (numeric value 2)The connection is in the closing handshake and is about to close. The connection is going through the closing handshake.3: Corresponding constant closed (numeric value 3)The connection is closed or not established at all. The connection have been closed or could not be opened.Example:var socket = new WebSocket (URL);if (socket.readystate!=1) {
alert ("Not connected. ");
return;
} According to Bufferedamount, you can know how many bytes of data are waiting to be sent, and if WebSocket has already called the Close method, the property will grow.
The "ReadyState" property of the WebSocket object records the status value during the connection