Web Sockets
WebSockets is a communication protocol that provides a persistent, full-duplex connection between a client and server over a single TCP connection, allowing both sides to send messages to each other at any time without the overhead of…
Definition
WebSockets is a communication protocol that provides a persistent, full-duplex connection between a client and server over a single TCP connection, allowing both sides to send messages to each other at any time without the overhead of repeated HTTP requests.
Overview
Traditional web communication follows a request-response pattern: the client asks, the server answers, and the connection closes. WebSockets replace that with a single long-lived connection, established through an HTTP "upgrade" handshake, after which either side can push messages to the other at any moment with minimal framing overhead. This full-duplex, low-latency channel is what makes real-time features — live chat, multiplayer game state, collaborative editing, live dashboards, and trading tickers — practical to build without constantly polling the server. Once the handshake completes, the protocol switches from `http`/`https` to `ws`/`wss` and the connection stays open until either side closes it or the network drops, at which point clients typically implement reconnect-and-resync logic. Because the connection is stateful, WebSocket servers need to manage many concurrent open connections efficiently, which is why they're commonly built with event-driven runtimes such as Node.js or paired with a load balancer and reverse proxy like Nginx configured to support connection upgrades and sticky sessions. WebSockets aren't the only real-time option: Server-Sent Events offer a simpler one-way server-to-client stream over plain HTTP when the client doesn't need to push data back, and gRPC streaming or WebRTC are alternatives for other latency or media-heavy use cases. Choosing between them usually comes down to whether communication needs to be bidirectional, how many concurrent connections the infrastructure must support, and whether existing HTTP-based tooling (proxies, caches, load balancers) needs to keep working unmodified.
Specification
- Persistent, full-duplex connection over a single TCP socket
- Established via an HTTP upgrade handshake, then switches to ws/wss
- Low overhead per message compared to repeated HTTP requests
- Both client and server can initiate messages at any time
- Requires explicit reconnect/resync handling on network drops
- Commonly paired with event-driven server runtimes for scale
Use Cases
History
The WebSocket protocol provides full-duplex, two-way communication between a browser and server over a single long-lived TCP connection, avoiding the overhead of repeatedly opening HTTP connections for real-time features like chat, live feeds, and multiplayer games. Standardization began after a 2009 IETF discussion and the January 2010 chartering of the HyBi (BiDirectional or Server-Initiated HTTP) Working Group, which iterated through numerous drafts before the protocol was published by the IETF as RFC 6455 in December 2011. WebSocket connections begin with an HTTP-based "upgrade" handshake, then switch to a compact binary framing layered over TCP. The browser-facing WebSocket API is standardized separately at the W3C/WHATWG.
Sources
- IETF — RFC 6455: The WebSocket Protocol · as of 2026-07-17
- WebSocket.org — WebSocket standards overview · as of 2026-07-17