WebSocket

The WebSocket ProtocolApplication layer · OSI 7

Full-duplex framed messaging upgraded from HTTP

Step 1 of 6: Open TCP socket on port 80. Calling new WebSocket("ws://www.example.com/chat") begins with an ordinary TCP handshake to port 80 . Production apps use wss:// over TLS on port 443; ws:// shows raw bytes.
0.0 s / 20.6 s
Your browser192.168.1.10
HandshakeRequestResponseDataControl

Overview

keeps one connection open between browser and server so either side can send messages immediately for chat, live scores, or games. It starts as an HTTP Upgrade request, then switches to tiny frames.

Defined in RFC 6455, WebSocket begins with an HTTP/1.1 Upgrade: websocket handshake (101 Switching Protocols) on port 80 (ws://) or TLS port 443 (wss://), then exchanges framed messages with 2-14 byte headers.

Key facts

Layer
Application (over TCP / TLS)
Ports
80 (ws://), 443 (wss://)
Handshake
HTTP Upgrade -> 101 Switching
Frame header
2 to 14 bytes (masked from client)
Defined in
RFC 6455

Upgraded HTTP became a two-way pipe

A single HTTP Upgrade handshake converted the TCP connection into a lightweight binary frame channel where either side could transmit messages immediately.

Completed RFC 6455 HTTP/1.1 101 Upgrade, bidirectional text frames, Ping/Pong keepalive, and status 1000 close handshake.

Upgrade
GET Upgrade -> 101 Switching
Control overhead
2 bytes minimum (Ping)
Push capability
Either side can send unprompted
Production
wss:// inside TLS (port 443)

Try it yourself

Inspect a WebSocket Upgrade handshake

Check the HTTP 101 Upgrade headers sent during an initial WebSocket negotiation.

curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" -H "Sec-WebSocket-Version: 13" https://echo.websocket.events