Skip to main content
>_ supraj.dev
TOPIC NETWORKING
WebSockets keeping a connection alive
IN 10 SECONDS

A protocol providing full-duplex communication over a single TCP connection. It starts as an HTTP request with an Upgrade header, then switches to a persistent binary stream.

GOTCHA Many cloud load balancers terminate idle connections after 60s. You must send periodic ping/pong frames to keep WebSockets alive.
HOW A WEBSOCKET UPGRADE FLOWS
01 Client sends HTTP GET with Connection: Upgrade and Upgrade: websocket.
02 Server responds with status 101 Switching Protocols if supported.
03 Session TCP socket stays open; both sides send framed data packets without HTTP header overhead.
04 Heartbeat ping/pong frames keep load balancers from killing the idle connection.
POKE IT YOURSELF
wscat -c ws://echo.websocket.org — connect and chat over WebSockets
websocat ws://localhost:8080 — CLI utility to pipe stdin to WebSockets