NETWORKING / A CONCEPT NOTE
WebSockets
keeping a connection alive
Overview · mechanism
pitfall · examples
01 / THE SHORT VERSION
The idea in a few sentences.
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.
02 / FOLLOW THE MECHANISM
How a websocket upgrade flows
Client
sends HTTP GET with Connection: Upgrade and Upgrade: websocket.
Server
responds with status 101 Switching Protocols if supported.
Session
TCP socket stays open; both sides send framed data packets without HTTP header overhead.
Heartbeat
ping/pong frames keep load balancers from killing the idle connection.
04 / COMMAND NOTES
Read the command, then the result.
Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.
connect and chat over WebSockets
wscat -c ws://echo.websocket.orgCLI utility to pipe stdin to WebSockets
websocat ws://localhost:808005 / CHECK YOURSELF
Could you explain WebSockets to a teammate?
Try it out loud in two sentences: what it is, and the one detail that changes the picture. If you stall, the gap is the part to reread.