Vol. I · No. 46The protocol sectionSat, 10 Oct 2026
Layer 7 · Web · a persistent two-way channel

WebSocket

Full-duplex over the web

WebSocket is the open line. HTTP is request-then-response — the server can’t speak unprompted. WebSocket upgrades a single HTTP connection into a persistent channel where either side can send a message at any time. It is how chat, live dashboards and multiplayer games stay in sync.

WebSocket starts as HTTP, then upgrades to a lasting channel where both ends push freely.

Operates at
Layer 7
over one TCP conn
Ports
80 · 443
ws:// · wss://
Direction
Full-duplex
both ways, anytime
Starts as
HTTP
then Upgrade: 101

How it works

The HTTP upgrade, then a channel that stays open
BrowserServer
HTTP GET with Upgrade: websocket
Connection: Upgrade · Sec-WebSocket-Key: …
A normal request on the same port — proxies and firewalls wave it through
101 Switching Protocols
Sec-WebSocket-Accept confirms the key — the connection is now a WebSocket
Messages flow both ways as framed data
Text / Binary framesthe payload
Ping / Pongkeep-alive
Closegraceful end

After the 101 the HTTP semantics fall away — no more requests and responses, just a stream of frames either side sends whenever it has something to say.

The main points

What WebSocket does, step by step

1
Handshake over HTTP

The client sends an Upgrade request; the server answers 101 and both switch off HTTP semantics.

2
Exchange frames

Small framed messages — text or binary — travel in either direction with almost no overhead.

3
Stay alive

Ping/Pong control frames keep the connection open through idle periods and detect a dead peer.

4
Close cleanly

Either end sends a Close frame with a status code; the app usually reconnects with backoff.

Why not just poll?
Polling — ask repeatedly, wasteful & laggy
SSE — server→client only, one way
WebSocket — both ways, one open socket

In cybersecurity

A long-lived channel that skips the usual per-request checks needs its own discipline — the browser’s same-origin rules don’t protect it the way they protect fetches.

Always use wss://

Plain ws:// is cleartext; wss:// runs the whole channel over TLS, just like HTTPS.

Cross-site hijacking

The handshake isn’t bound by CORS — check the Origin header and use a token, not just a cookie.

Authenticate the upgrade

Auth happens once at connect — validate it there, and re-check authorization on sensitive messages.

Validate every frame

Messages arrive outside the request pipeline, so input validation must live in the socket handler.

Resource exhaustion

Idle open sockets tie up memory; cap connections per user and time out the silent ones.

Proxy blind spot

Many WAFs inspect the handshake but not the frames — put message-level checks on the server.

Rides in the stack

TCPTLSHTTPWS

It borrows HTTP just long enough to open on port 443, then keeps that TCP connection for itself.

Works with

HTTPTLS

Frames & schemes

Frame types
TextUTF-8
Binarybytes
Ping/Pongalive
Closecode
Schemes
ws://80
wss://443 · TLS
Upgrade101
Origincheck