docs.rodeo

MDN Web Docs mirror

The WebSocket API (WebSockets)

{{DefaultAPISidebar("WebSockets API")}} {{AvailableInWorkers}} 

The WebSocket API makes it possible to open a two-way interactive communication session between the user’s browser and a server. With this API, you can send messages to a server and receive responses without having to poll the server for a reply.

The WebSocket API provides two alternative mechanisms for creating and using web socket connections: the {{domxref("WebSocket")}}  interface and the {{domxref("WebSocketStream")}}  interface.

Additionally, the WebTransport API is expected to replace the WebSocket API for many applications. WebTransport is a versatile, low-level API that provides backpressure and many other features not supported by either WebSocket or WebSocketStream, such as unidirectional streams, out-of-order delivery, and unreliable data transmission via datagrams. WebTransport is more complex to use than WebSockets and its cross-browser support is not as wide, but it enables the implementation of sophisticated solutions. If standard WebSocket connections are a good fit for your use case and you need wide browser compatibility, you should employ the WebSockets API to get up and running quickly. However, if your application requires a non-standard custom solution, then you should use the WebTransport API.

[!NOTE] While a WebSocket connection is functionally somewhat similar to standard Unix-style sockets, they are not related.

Interfaces

The HTTP headers are used in the WebSocket handshake:

Guides

Tools

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN