WebSocket Protocol: HTTP Upgrade and Frames
WebSocket begins with an HTTP opening handshake and then carries bidirectional frames over a persistent connection. It is not simply repeated HTTP polling.
Updated · Editorial approach and simulation limits
The opening handshake starts as HTTP
A client sends an HTTP request with Upgrade and connection headers plus a WebSocket key. A server that accepts the upgrade returns a switching-protocols response with a computed accept value. If that response is missing or invalid, the connection has not completed the WebSocket opening handshake.
The HTTP handshake can include an origin, requested subprotocols and extensions. A reverse proxy must preserve the required upgrade behavior; otherwise a normal HTTP response can appear even though the origin server supports WebSocket.
Frames carry messages in both directions
After upgrade, peers exchange frames with an opcode, payload length and control bits. Text and binary data frames carry application messages; continuation frames can compose fragmented messages; Ping and Pong support liveness checks; Close begins connection shutdown.
Client-to-server frames are masked as required by the protocol. A WebSocket message may span multiple frames, so interpret fragmentation and continuation state before treating a frame as a complete application message.
ws, wss and intermediary behavior
The ws scheme uses a plain WebSocket connection; wss protects the connection with TLS. With wss, network observers can see the endpoints and timing but not frame contents without authorized decryption.
WebSocket keeps a connection open for bidirectional messaging, while HTTP requests usually complete with a response and can use separate mechanisms for streaming. Inspect upgrade status, proxy timeouts, Ping/Pong and Close frames when a real-time session drops.
Explore WebSocket interactively
Follow the matching exchange packet by packet. The animation is a scripted teaching model with illustrative timing, not a capture of your network.
Specification and source
For exact protocol requirements, consult the primary document: RFC 6455: The WebSocket Protocol. This page summarizes selected behavior and is not a substitute for the specification.
Related protocol lessons
Browse all application protocols · Compare an upgraded connection with request-response HTTP