Web Protocols

What is WebSocket?

Definition

WebSocket is a protocol providing a full-duplex bidirectional communication channel between a client (typically a browser) and a server over a single long-lived TCP connection, defined in RFC 6455.

WebSocket is a standard protocol that enables interactive communication between a user's browser and a server. Unlike the traditional HTTP request-response model, WebSocket provides a full-duplex, bidirectional channel over a single TCP connection. This allows the server to push data to the client at any time without the client having to poll or send repeated requests. The protocol was standardized as RFC 6455 by the IETF in December 2011.

A WebSocket connection starts with an HTTP upgrade handshake. The client sends an HTTP request with an `Upgrade: websocket` header and a `Sec-WebSocket-Key` header containing a base64-encoded random value. The server responds with an HTTP 101 Switching Protocols status, a `Sec-WebSocket-Accept` header containing a hash of the key, and the connection transitions from HTTP to the WebSocket protocol. After the handshake, both endpoints can send and receive data frames (text or binary) over the same TCP socket until one side closes the connection with a close frame.

WebSocket operates at the application layer but relies on TCP for transport. It uses port 80 for ws:// and port 443 for wss:// (WebSocket over TLS). The protocol includes a lightweight framing mechanism with a small header (as little as 2 bytes plus mask key) to minimize overhead. It supports subprotocol negotiation (e.g., for STOMP or MQTT over WebSocket) and extension negotiation (e.g., for compression, as defined in RFC 7692). WebSocket is widely used in real-time web applications: chat systems, live sports scores, financial tickers, collaborative editing, and multiplayer games.

Key facts

  • RFC 6455 (December 2011) defines the WebSocket protocol.
  • Uses an HTTP Upgrade handshake to switch from HTTP to WebSocket.
  • Supports text and binary data frames over a single TCP connection.
  • wss:// (WebSocket Secure) runs over TLS on port 443.
  • WebSocket is standardized by the W3C for browser APIs (WebSocket API).

How it works in practice

A financial dashboard uses WebSocket to display real-time stock prices. The browser connects to wss://trading.example.com/prices. Once the handshake completes, the server pushes price updates every 100 milliseconds as small JSON frames. The user never sees stale data, and the server does not waste bandwidth on HTTP polling overhead. If the connection drops, the client attempts to reconnect with a short delay.

Related terms

HTTP Server-Sent Events (SSE) TCP TLS RFC 6455 WebSocket API

References

More in Web Protocols

CORS

CORS (Cross-Origin Resource Sharing) is a browser security mechanism that lets servers explicitly allow web pages from one origin to request resources from a different origin via HTTP response headers.

GraphQL

GraphQL is a query language and runtime for APIs that lets clients request exactly the data they need in a single round trip, reducing over-fetching and under-fetching.

gRPC

gRPC is a high-performance, open-source remote procedure call framework initially developed by Google. It uses HTTP/2 for transport, Protocol Buffers as its interface definition language and message serialization format, and supports bidirectional streaming.

HTTP

HTTP is a text-based request-response protocol that defines how web clients and servers exchange resources, forming the foundation of data communication on the World Wide Web.

HTTP Pipelining

HTTP Pipelining is a technique in HTTP/1.1 that sends multiple requests on a single connection without waiting for each response, now largely replaced by HTTP/2 multiplexing.

HTTP Status Code

A three-digit integer in an HTTP response that indicates the result of the server's attempt to process the request, grouped into five classes (1xx through 5xx).

HTTP/1.1

HTTP/1.1 is the persistent-connection version of the Hypertext Transfer Protocol, defined in RFC 2616 and updated by RFCs 7230-7235, enabling multiple requests and responses over a single TCP connection.

HTTP/2

HTTP/2 is a binary, multiplexed version of HTTP that reduces latency through header compression, stream prioritization, and server push, as defined in RFC 7540.

HTTP/3

HTTP/3 is the third major version of the Hypertext Transfer Protocol, which runs over QUIC instead of TCP to reduce latency, eliminate head-of-line blocking, and improve connection setup time.

HTTPS

HTTPS (HTTP Secure) is HTTP traffic encrypted inside a TLS session, protecting data confidentiality, integrity, and server authenticity between a client and a web server.

Who Is Online

In total there are 67 users online: 0 registered, 59 guests and 8 bots.

Most users ever online was 5,555 on 17 Jul 2026, 3:23 am.

Bots: AhrefsBot Applebot Baiduspider Bingbot Other Bot Other Crawler PetalBot SemrushBot

Users active in the past 15 minutes. Total registered members: 369