Implement a WebSocket Server Handler
Build a complete WebSocket server with connection management, rooms, broadcasting, and reconnection logic.
The Prompt
Implement a WebSocket server for the following use case. Include: 1. Connection handling and authentication (JWT validation on connect) 2. Room/channel management (join, leave, list) 3. Message broadcasting (to room, to specific user, to all) 4. Heartbeat/ping-pong for connection health 5. Graceful disconnection handling 6. Client-side reconnection with exponential backoff 7. Message schema/type definitions Framework: [SOCKET.IO / WS / FASTAPI WEBSOCKETS — specify] Use case: [DESCRIBE — e.g., Real-time collaborative document editing where multiple users can be in the same document room and see each other's cursor positions and changes] Language: [NODE.JS / PYTHON]
Example Output
Built a Socket.IO server with JWT auth middleware on the handshake, document rooms keyed by documentId, cursor position broadcasting with 50ms throttle to prevent flooding, heartbeat interval of 30s with automatic cleanup of stale connections, and a typed MessageSchema union.
FAQ
Which AI model is best for Implement a WebSocket Server Handler?
Claude Sonnet 4 — handles stateful, event-driven code well with good architectural reasoning.
How do I use the Implement a WebSocket Server Handler prompt?
Copy the prompt, replace the [BRACKETED] placeholders with your specific information, and paste into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.). Built a Socket.IO server with JWT auth middleware on the handshake, document rooms keyed by documentId, cursor position broadcasting with 50ms throttle to prevent flooding, heartbeat interval of 30s with automatic cleanup of stale connections, and a typed MessageSchema union.
Model Recommendation
Claude Sonnet 4 — handles stateful, event-driven code well with good architectural reasoning.