About WebSockets Issues:

Source: Internet
Author: User

WebSockets is a full-duplex, two-way communication channel with the server, it does not use the HTTP protocol, he has his own protocol that is the custom protocol, the WS protocol, its security protocol for the WSS Protocol. This protocol is specifically designed for fast transmission of small data. There is a requirement for the service that the server must support the protocol, that is, a specific server is required to work.

Websockets API:

(1) First instantiate an object: the var socket = new WebSocket (URL) is followed by the URL that needs to be connected;

(2) There are four states: Socket.readystate= websocket.opening (0) establishing a connection

=websocket.open (1) A connection has been established

=websocket.closing (2) Closing the connection

=websocket.close (3) Closed connection

(3) method of the object: Socket.send (String) string is the passed-in data, and is a string format

Socket.close () Close the connection

(4) Event:

Socket.onmessage=function (event) {

var data =event.data;

}

When the server sends a message to the client, it triggers the messages event, where the data is stored in the Event.data property and the returned data is in string format.

Other events: Socket.onopen;socket.onclose;socket.onerror;

About WebSockets Issues:

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.