NETWORKING / A CONCEPT NOTE

WebSockets

keeping a connection alive

~65 sec read

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

  1. Client

    sends HTTP GET with Connection: Upgrade and Upgrade: websocket.

  2. Server

    responds with status 101 Switching Protocols if supported.

  3. Session

    TCP socket stays open; both sides send framed data packets without HTTP header overhead.

  4. 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.

EXAMPLE 01 · REFERENCE

connect and chat over WebSockets

wscat -c ws://echo.websocket.org

EXAMPLE 02 · REFERENCE

CLI utility to pipe stdin to WebSockets

websocat ws://localhost:8080

Explore command anatomy in the CLI lab