indexClient in C#client#c#terminal#websocket

Client in C

The first of the two clients that give this atlas its name: a real terminal client for the chat, in C, talking the exact WebSocket protocol built in websocket-protocol-from-scratch. The interesting problem here isn't the network code — it's the UI loop. A chat client has two independent sources of activity, keyboard input and incoming network messages, and neither can be allowed to block the other; this branch builds that loop with poll/select, parses WebSocket frames from the client side (which has its own asymmetry from the server side — a client masks its outgoing frames, a server doesn't), and adds reconnection with exponential backoff so a dropped connection doesn't mean a dead client.

Planned notes

  • The client-side WebSocket handshake: sending the Upgrade request, generating Sec-WebSocket-Key, and verifying the server's Sec-WebSocket-Accept
  • Parsing frames from the client side: what's symmetric with the server implementation and what isn't (masking direction, primarily)
  • A non-blocking terminal UI: raw mode input, and why line-buffered stdin breaks a chat client
  • The poll/select loop serving keyboard input and socket data at the same time, without a dedicated thread for either
  • Rendering incoming messages without corrupting whatever the user is currently typing
  • Handling ping/pong and unsolicited close frames from the server correctly while the user is mid-input
  • Detecting a dropped connection and reconnecting with exponential backoff instead of a tight retry loop
  • Resuming into a room's state (presence, recent history) after a reconnect, not just re-opening the socket
  • A minimal .chatrc for server address, room, and display name
  • Comparing this client's code size and complexity directly against the TypeScript client in the next branch

Core sources

  • Atlas I and II's terminal I/O material — continuation of the non-blocking stdin handling patterns used there.
  • man poll, man select — the loop primitives for this client.
  • RFC 6455 — the client-side sections specifically (masking direction, close-handshake initiation from a client).

Connects to: WebSocket Protocol from Scratch · Client in TypeScript