On this page

Connection management

Handle subscription errors and restore connections when network issues occur.

icon

Usage in Blueprints and C++


Asynchronous and synchronous method execution

Most PubNub Unreal SDK methods are available in both asynchronous and synchronous variants.

  • Asynchronous methods (Async suffix) return void and take an optional delegate parameter that fires when the operation completes.

    1Chat->ReconnectSubscriptionsAsync(OnReconnectSubscriptionsResponseDelegate);

    You can also use native callbacks that accept lambdas instead of dynamic delegates. Native callback types have the Native suffix (for example, FOnPubnubChatOperationResponseNative).

  • Synchronous methods (no suffix) block the main game thread until the operation completes and return a result struct directly.

    1FPubnubChatOperationResult Result = Chat->ReconnectSubscriptions();

Connection status listener

Monitor connection status in real time to track subscription state and react to network or authentication errors.

Method signature

Connection status types

The connection status listener reports the following status types:

StatusDescription
PCCS_ConnectionOnline
The connection has been established and is ready to receive real-time updates.
PCCS_ConnectionOffline
The connection has been intentionally terminated.
PCCS_ConnectionError
The connection was unexpectedly lost or failed to establish. Contains error details.

Sample code

Reference code

This example is a self-contained code snippet ready to be run. Set up your Unreal project and follow the instructions in the lines marked with ACTION REQUIRED before running the code. Use it as a reference when working with other examples in this document.

Set up a connection status listener to monitor connection changes.

Actor.h
1

Actor.cpp
1

Reconnect subscriptions

Restore previous subscriptions with all subscribed channels and listeners. Call after DisconnectSubscriptions() or when receiving PCCS_ConnectionError.

Method signature

1Chat->ReconnectSubscriptions(FString Timetoken = "");
* required
ParameterDescription
Timetoken
Type: FString
Default:
""
Optional timetoken to resume subscriptions from a specific point. If empty, resumes from the current time.

Output

TypeDescription
FPubnubChatOperationResult
Operation result with Error (bool), ErrorMessage (FString), and StepResults (per-step details).

Sample code

Reconnect all subscriptions after a connection error.

1

Other examples

Reconnect with connection status listener

Actor.h
1

Actor.cpp
1

Disconnect subscriptions

Pause all active subscriptions and listeners.

Method signature

1Chat->DisconnectSubscriptions();

Output

TypeDescription
FPubnubChatOperationResult
Operation result with Error (bool), ErrorMessage (FString), and StepResults (per-step details).

Sample code

Disconnect all subscriptions when you want to pause real-time updates.

1

Troubleshooting

Recommended workflow for handling subscription errors:

  1. Initialize monitoring: Add the connection status listener immediately after creating the Chat instance.
  2. Handle errors: On PCCS_ConnectionError, call ReconnectSubscriptions().
  3. Manual control: Call DisconnectSubscriptions() when pausing real-time updates (for example, when the app backgrounds).
  4. Restore connection: Call ReconnectSubscriptions() to resume.

This pattern maintains stable connectivity and automatic recovery from network issues.