DocumentationCore Protocol

Connection State Recovery

When a client disconnects and reconnects, PaindaProtocol can automatically replay all missed messages and restore room memberships. No manual bookkeeping needed.

Enable on Server

const server = new PPServer({
  port: 3000,
  recovery: true,           // Enable with defaults
});

// Or configure:
const server = new PPServer({
  port: 3000,
  recovery: {
    maxBufferSize: 200,     // Max messages to buffer per client
    retentionMs: 120_000,   // Keep data for 2 minutes after disconnect
  },
});

Client Side

const client = new PPClient({
  url: "ws://localhost:3000",
  reconnect: true,
});

client.on("recovery", ({ sid, recovered, missedCount }) => {
  if (recovered) {
    console.log(`Session restored! ${missedCount} messages replayed.`);
  }
});

// After reconnect, the client automatically:
// 1. Sends its session ID and last message offset
// 2. Receives all missed messages in order
// 3. Rejoins all previous rooms

Recovery is transparent — the client continues as if the disconnect never happened. If the retention window expires, a fresh session is created instead.

Next: Scaling with Adapters