All documentation
WebSockets

Realtime WebSockets: Connect, Send and Stay Healthy

Connect Node, browser and Python clients, send events, understand automatic heartbeat pings and handle reconnects.

Multi-language

Overview

PulseGrid realtime uses WebSockets for low-latency two-way communication. SDK 0.2.0 automatically keeps connections healthy with heartbeat pings. The server answers with pong messages. Repeated pong traffic at the heartbeat interval is normal and does not mean the user clicked Ping repeatedly. The JavaScript server SDK, JavaScript browser client and Python SDK can all connect to the same channel and receive the same broadcast event.

Setup

Trusted server realtime: 1. Create a short-lived client token for the connection identity. 2. Call channel(...).connect(...). 3. Listen for messages/events. 4. Send text or custom events. 5. Close cleanly when finished. Browser realtime: Use pulsegrid/client. It automatically reconnects, backs off after failures, sends heartbeat pings and queues outgoing messages while reconnecting. Heartbeat: - Automatic ping/pong traffic is connection maintenance. - Manual ping() is useful for diagnostics. - Business UIs should normally hide heartbeat traffic from the main message feed.

Code example

Realtime WebSockets: Connect, Send and Stay Healthy
Node.js server realtime
const token = await pg.tokens.create({
  identifierId: "dispatch_server",
  allowedChannels: ["operations"],
});

const connection = await pg.channel("operations").connect({
  clientToken: token,
  onMessage: payload => console.log(payload),
});

connection.send("Dispatch online");
connection.sendEvent("delivery.updated", {
  data: { order_id: "ORD-1042", status: "in_transit" },
});
connection.ping();

Notes

Reconnect and heartbeat are safety features, not application events. For observability, show connection state, last heartbeat, reconnect count and latency separately from business messages. If the same event ID appears on two connected clients, that proves both received the same PulseGrid broadcast event.