19 – Cleaning Up When the Server Shuts Down

A WebSocket app that keeps a little state per connection (the messages it received) and saves it when the connection ends:

Quick Start

1. Start the server:

pagi-server --app examples/19-shutdown-cleanup/app.pl --port 5000

2. Connect two clients and type a few lines in each:

websocat ws://127.0.0.1:5000/

Each line is answered with noted: N.

3. Stop the server with Ctrl+C. The log shows each session ending with server shutdown, code 1012, then saved N message(s) for each, and only then shutdown: 2 session(s) saved.

Close a client yourself instead and its session ends with client left.

Spec References