The WebSocket API (WebSockets) - Web APIs | MDN (original) (raw)

Interfaces

WebSocket

The primary interface for connecting to a WebSocket server and then sending and receiving data on the connection.

WebSocketStream Non-standard

Promise-based interface for connecting to a WebSocket server; uses streams to send and receive data on the connection.

CloseEvent

The event sent by the WebSocket object when the connection closes.

MessageEvent

The event sent by the WebSocket object when a message is received from the server.

The HTTP headers are used in the WebSocket handshake:

Sec-WebSocket-Key

An HTTP request header that contains a nonce from the client. This is used in the WebSocket opening handshake to verify that the client explicitly intends to open a WebSocket. It is added automatically by the browser.

Sec-WebSocket-Accept

An HTTP response header used in the WebSocket opening handshake to indicate that the server is willing to upgrade to a WebSocket connection. The value in the directive is calculated from the value of Sec-WebSocket-Key in the corresponding request.

Sec-WebSocket-Version

An HTTP header that in requests indicates the version of the WebSocket protocol understood by the client. In responses, it is sent only if the requested protocol version is not supported by the server, and lists the versions that the server supports.

Sec-WebSocket-Protocol

An HTTP header that in requests indicates the sub-protocols supported by the client in preferred order. In responses, it indicates the sub-protocol selected by the server from the client's preferences.

Sec-WebSocket-Extensions

An HTTP header that in requests indicates the WebSocket extensions supported by the client in preferred order. In responses, it indicates the extension selected by the server from the client's preferences.

Guides

Specifications

Specification
WebSockets # the-websocket-interface

Browser compatibility

api.WebSocket

api.WebSocketStream

See also