Heartbeat
To keep the connection alive and allow the server to detect disconnected clients, a standard ping/pong heartbeat mechanism is used.
Server
ping: The server will send apingmessage to your client every 25 seconds.Server Message:
{"event":"ping"}
Client
pong: Upon receiving aping, your client must respond with apongmessage within 10 seconds.Client Response:
{"op":"pong"}
If the server does not receive a pong response from your client within 10 seconds after sending a ping, it will consider the connection stale and will terminate it.
💡 Developer Tip
Most modern WebSocket client libraries (e.g., the browser's
WebSocketAPI, Python'swebsocketslibrary) handleping/pongframes automatically. You typically do not need to implement this logic manually. Just ensure your network firewall allows WebSocket control frames to pass through.
Last updated