Skip to main content
This guide covers the full lifecycle of a Rhombus WebSocket connection: establishing the connection, performing the STOMP handshake, maintaining the connection with heartbeats, and handling disconnections gracefully.

Lifecycle Overview

Step 1: WebSocket Handshake

Initiate a secure WebSocket connection to the Rhombus endpoint with authentication headers:
A successful handshake upgrades the HTTP connection to WebSocket. If authentication fails, the server returns an HTTP error (401/403) before the upgrade completes.

Step 2: STOMP CONNECT

After the WebSocket connection is established, send a STOMP CONNECT frame to initialize the messaging protocol:

CONNECT Frame

Expected Response: CONNECTED Frame

The server echoes back the negotiated version and heartbeat intervals.

Building STOMP Frames

STOMP frames follow a simple text-based format:
  • Each frame starts with a command name
  • Headers are key-value pairs separated by colons, one per line
  • An empty line separates headers from the body
  • The frame ends with a null byte (\x00)

Step 3: Subscribe to a Topic

After the STOMP connection is established, subscribe to the organization change topic:

SUBSCRIBE Frame

Replace {orgUuid} with your organization’s UUID. Retrieve it via the REST API endpoint POST /api/org/getOrgV2.

Step 4: Message Loop and Heartbeats

Once subscribed, your application enters a message loop where it:
  1. Receives MESSAGE frames containing event data
  2. Sends heartbeats to keep the connection alive
  3. Receives heartbeats from the server

Heartbeat Mechanism

Heartbeats are single newline characters (\n) sent at the negotiated interval (10 seconds). Both the client and server send heartbeats. If either side stops receiving heartbeats, the connection is considered dead.

Parsing Incoming Frames

Message Loop

Step 5: Graceful Disconnection

Before closing the WebSocket, send a STOMP DISCONNECT frame:
This signals to the server that the client is intentionally disconnecting, allowing it to clean up resources immediately rather than waiting for a heartbeat timeout.

Reconnection Strategy

Network interruptions are inevitable. Implement automatic reconnection with backoff:

Full Reconnection Loop

Connection Timeouts

Common Issues

Last modified on April 29, 2026