NAME
Multi-User Chat using PAGI::WebSocket
SYNOPSIS
pagi-server --app examples/websocket-chat-v2/app.pl --port 5000
DESCRIPTION
This is a port of the examples/10-chat-showcase application that demonstrates how PAGI::WebSocket simplifies WebSocket handling.
The HTTP, SSE, and State modules are identical to the original. Only the WebSocket handler is rewritten to use PAGI::WebSocket.
Compare lib/ChatApp/WebSocket.pm with the original at examples/10-chat-showcase/lib/ChatApp/WebSocket.pm to see the improvements.
Key Differences
WebSocket handler uses
PAGI::WebSocket->newwrapperConnection accepted with
$ws->acceptinstead of raw protocolCleanup registered with
$ws->on_closecallbackMessage loop uses
$ws->each_jsonfor cleaner iterationSending uses
$ws->send_jsoninstead of raw JSON encoding
ENDPOINTS
Same as the original:
- GET / - Chat frontend
- GET /api/rooms - List rooms
- GET /api/room/:name/history - Room message history
- GET /api/stats - Server statistics
- WS /ws/chat - WebSocket chat endpoint
- SSE /events - Server-Sent Events stream