The "ReadyState" property of the WebSocket object records the status value during the connection

Source: Internet
Author: User

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

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.