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

ts
const delay = nextDelay(attempt);
attempt += 1;
reconnectTimer = setTimeout(connect, delay);

const socket = new WebSocket(url);
socket.onclose = scheduleReconnect;

Learn this concept

Lesson 5.10 · Reconnecting WebSocket hooks

Used in exercises

Exercise 5.12 · Rider mode and customer tracking screens Exercise 5.15 · Per-user Redis replay log Exercise 5.17 · Rider map geometry library