WebSockets
WebSockets provides full-duplex communication over a single TCP socket. WebSockets is a component of HTML5, designed to replace existing push-based technologies with the aim of reducing latency and network traffic between client and server.
The protocol operates in two parts:
- First, a handshake is exchanged between client and server (as an HTTP Upgrade request).
- Next, data is transferred back and forth in messages that are composed of one or more frames, each having a specified type (for example, UTF-8 text, binary data, or control frames) that is the same for each frame in a message.
The WebSockets protocol is designed on the principle that there should be minimal framing (the only framing that exists is to make the protocol frame-based instead of stream-based, and to support a distinction between Unicode text and binary frames). It is expected that metadata would be layered on top of WebSocket by the application layer, in the same way that metadata is layered on top of TCP by the application layer (for example, HTTP).
Conceptually, WebSockets is a layer on top of TCP that:
- Adds a web origin-based security model for browsers.
- Adds an addressing and protocol naming mechanism to support multiple services on one port and multiple host names on one IP address.
- Layers a framing mechanism on top of TCP to get back to the IP packet mechanism that TCP is built on, but without length limits
- Includes an extra closing handshake in-band that is designed to work in the presence of proxies and other intermediaries.
WebSockets is ideal for the following types of applications:
- Gaming
- Stock ticker
- Traffic updates
- Telemetry data (MQTT over WebSocket)
- Mobile payments
- Mobile app gateway
- Scoring