Reconnecting WebSocket
A reconnecting WebSocket is a client-side connection manager that automatically attempts to establish a new WebSocket connection after an unexpected disconnection. In this course, it uses exponential backoff with jitter to retry connections without overwhelming the backend.
Minimal example
const delay = nextDelay(attempt);
attempt += 1;
reconnectTimer = setTimeout(connect, delay);
const socket = new WebSocket(url);
socket.onclose = scheduleReconnect;