Introduction to Javascript WebSocket usage by example (a brief introduction tutorial)

  • 2020-03-30 02:37:50
  • OfStack

WEB Socket properties:

attribute instructions Socket. The readyState The connection state of the ReadOnly attribute that readyState represents. It can have the following values:

A value of 0 indicates that the connection has not yet been established.

A value of 1 indicates that connection establishment and communication is possible.

A value of 2 indicates that the connection is through and the handshake will end.

A value of 3 indicates that the connection is closed or cannot be opened.

Socket. BufferedAmount The bufferedAmount that reads the property represents the number of bytes of text, and the queue for utf-8 USES the send() method.

WEB Socket event:

The event The handler instructions The open Socket. The onopen This event occurs when a socket establishes a connection. The message Socket. The onmessage When this event occurs, the client receives data from the server. The error Socket. The onerror There were any communication errors when this event occurred. The close Socket. Onclose This event occurs when the connection closes.

WEB Socket method:

methods instructions Socket. The send () The send (data) method is used to connect the transmitted data. Socket. The close () The close () method will be used to terminate any existing connections.


Related articles: