Part I. Examples

This part walks through the example programs in the companion websockets-examples repository. Each chapter takes one complete, compilable program and explains it from top to bottom. The source shown in each chapter is generated directly from that repository, so the listings always match real, building code.

The programs progress from the synchronous client, through the optional messaging layer, to the asynchronous server in its several forms, and conclude with a set of more advanced, production-oriented examples.

The programs share a small support header, vwsx.h (its bodies in libvwsx) — the examples' analog of APUE's apue.h. It is a thin convenience layer that keeps each program uncluttered without hiding the real libvws API: every example still makes the actual vws_* calls. It provides just three helpers. vwsx_die prints a message and exits on an unrecoverable setup failure. vwsx_connect opens a client connection — vws_cnx_new() followed by vws_connect(), dying on failure — and returns a connected vws_cnx that the caller drives with the real API. vwsx_serve_stop_on_signal installs SIGINT/SIGTERM handlers that stop a running server gracefully through vws_tcp_svr_stop(); it is called with the server cast to (vws_tcp_svr*), since only the base server exposes a stop entry point.