Selected work
Real-Time NetworkingC · Winsock2 · GCC

cWS — Tiny WebSocket Echo Server & Client

Single-file C WebSocket server and client with sub-microsecond RTT benchmarking and detailed performance reporting.

A minimal WebSocket echo server and client for Windows, self-contained in two C files. Ships with a benchmarking mode that measures round-trip latency down to microsecond precision using QueryPerformanceCounter.

Role — Solo developer
  • C
  • Winsock2
  • Windows (QueryPerformanceCounter)
  • GCC/MinGW
  • SHA-1
  • Base64
  • WebSocket (RFC 6455)

cWS implements a full WebSocket server and client from scratch in C with zero external dependencies beyond Winsock2 (built into Windows). The server listens on ws://127.0.0.1:8080 and accepts a single client connection; the client can run in interactive mode (read stdin and echo back responses) or benchmark mode (send and measure round-trip time). Both encode the WebSocket handshake using inline SHA-1 and Base64, avoiding a dependency on OpenSSL or similar.

The benchmark mode is the main draw. The client can pump N messages of configurable size through the connection, timing each round-trip with QueryPerformanceCounter (Windows high-resolution timer). It then sorts the RTTs and reports min, max, average, p50, p95 latency, messages per second, and throughput in MB/s. On localhost Windows, a 64-byte payload achieves ~19,793 msgs/sec with 50.5µs average RTT; a 16 KB payload hits ~7,942 msgs/sec with 125.8µs latency.

Intended for measuring WebSocket performance overhead on Windows without the complexity of a full framework or test harness. The single-file approach makes it trivial to compile and modify; no headers to hunt down, no build configuration beyond a batch script. Useful for performance debugging or as a baseline for what bare-metal Winsock2 WebSocket can sustain.

What's notable
  • Hand-rolled SHA-1 and Base64 for WebSocket handshake—no external crypto dependencies
  • QueryPerformanceCounter-based RTT measurement with sub-microsecond precision
  • Dual-mode operation: interactive text echo for manual testing, benchmark mode with histogram-style latency stats
  • Supports variable payload sizes up to ~64 KB with configurable iteration counts
  • Single C file per role (server/client); builds in seconds with GCC and -lws2_32