Skip to main content

Connection

Overview

Reliable connection management is essential for maintaining uninterrupted communication between your client and our messaging network. Our system is designed to gracefully handle intermittent network disruptions and ensure message delivery without requiring manual intervention.

The Client SDK automatically manages connection state, reconnection attempts, and message synchronization, so you can focus on your application logic without worrying about network instability or data loss.


Connection State & Recovery

Automatic Reconnection

  • When a disconnection occurs due to network issues, the client automatically attempts to reconnect for up to 2 minutes.
  • During this window, the client stays in a reconnecting state, repeatedly trying to restore connectivity before eventually closing the connection if reconnection fails.

Message Handling During Reconnection

  • Messages published during the reconnecting phase are queued and sent automatically as soon as the connection is restored.
  • If the connection closes after the retry period, any unsent messages in the queue are discarded to prevent stale data delivery.

Subscriber Message Recovery

  • Subscribers who miss messages while attempting to reconnect will receive all missed messages immediately upon successful reconnection.
  • This ensures no message loss for subscribed topics, preserving data consistency even through brief interruptions.

Connection Management with Client SDK

Our Client SDK simplifies connection management to deliver a reliable, low-latency messaging experience. It abstracts the complexities of network state transitions and provides easy-to-use methods and event hooks to control and monitor the connection lifecycle, allowing you to concentrate on your application's core features.

Establishing a connection

info

The API keys in the code below are the keys you loaded during the interactive demo

The code snippet below demonstrates how to establish a connection with the Relay Network.

// Select a platform to see code

Connection Listeners

The Client SDK provides a set of connection event listeners that allow your application to respond dynamically to changes in connection state. Leveraging these listeners helps you build a more resilient and user-friendly experience by reacting promptly to connectivity events.

  • CONNECTED
    Fired when the client successfully establishes a connection to the server. Use this event to trigger any initialization logic, enable UI elements, or start sending messages.

    // Select a platform to see code
  • RECONNECT
    This event covers the lifecycle of reconnection attempts and has three states:

    • RECONNECTING: Fired when the client begins attempting to restore a lost connection. You can use this to inform users that the app is trying to reconnect.
    • RECONNECTED: Fired immediately after the client successfully re-establishes the connection. At this point, queued messages are sent, and subscriptions resume normally.
    • RECONN_FAIL: Fired when the client fails to reconnect within the allowed 2-minute window. This signals a permanent disconnection until manual intervention or a new connection attempt.

    // Select a platform to see code
  • DISCONNECTED
    Emitted when the connection is closed intentionally (e.g., client calls a disconnect method) or after failed reconnection attempts. This event can be used to disable message sending, alert users, or trigger cleanup routines.

    // Select a platform to see code

By hooking into these listeners, you gain full visibility and control over the connection lifecycle, enabling responsive UI updates and robust handling of network conditions.

Closing a Connection

The code snippet demonstrates how to close the connection between the client & the Relay Network.

// Select a platform to see code


Need Help?

Join our Discord server, post your concern & someone from our team will help you out ✌️