← All notes

WebSocket keepalive, ping/pong and reconnecting clients

Answer: Idle WebSocket connections get cut: HTTP/1.1 infrastructure closes idle connections after 30 to 120 seconds, so proxies may end a WebSocket early. Ping and Pong frames provide keepalive and heartbeat.

Python websockets

Node ws

Ping messages can verify that a remote endpoint is still responsive. The ws example sets isAlive = true on pong; its interval does if (ws.isAlive === false) return ws.terminate(), then ws.isAlive = false; ws.ping().

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: python-websockets/websockets (GitHub), Keepalive and latency (websockets docs), BSD-3-Clause (https://raw.githubusercontent.com/python-websockets/websockets/main/LICENSE). Copyright (c) Aymeric Augustin and contributors; python-websockets/websockets (GitHub), Client FAQ (websockets docs), BSD-3-Clause (https://raw.githubusercontent.com/python-websockets/websockets/main/LICENSE). Copyright (c) Aymeric Augustin and contributors; websockets/ws (GitHub), ws README, MIT (https://raw.githubusercontent.com/websockets/ws/master/LICENSE). Copyright (c) 2011 Einar Otto Stangvik; (c) 2013 Arnout Kazemier and contributors; (c) 2016 Luigi Pinca and contributors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: python-websockets/websockets (GitHub), Keepalive and latency (websockets docs), BSD-3-Clause (https://raw.githubusercontent.com/python-websockets/websockets/main/LICENSE). Copyright (c) Aymeric Augustin and contributors; python-websockets/websockets (GitHub), Client FAQ (websockets docs), BSD-3-Clause (https://raw.githubusercontent.com/python-websockets/websockets/main/LICENSE). Copyright (c) Aymeric Augustin and contributors; websockets/ws (GitHub), ws README, MIT (https://raw.githubusercontent.com/websockets/ws/master/LICENSE). Copyright (c) 2011 Einar Otto Stangvik; (c) 2013 Arnout Kazemier and contributors; (c) 2016 Luigi Pinca and contributors.

Cite this

Permanent ID: iil:note:2eee2efv

iinventedlight. 2026. "WebSocket keepalive, ping/pong and reconnecting clients." iinventedlight Library, iil:note:2eee2efv, version of 2026-11-16. https://iinventedlight.com/library/notes/websockets-keepalive-and-reconnect/. License: CC-BY-4.0.

@misc{iil_note_2eee2efv,
  author = {{iinventedlight}},
  title = {{WebSocket keepalive, ping/pong and reconnecting clients}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-16},
  url = {https://iinventedlight.com/library/notes/websockets-keepalive-and-reconnect/},
  note = {Permanent ID iil:note:2eee2efv. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/websockets-keepalive-and-reconnect.md.