> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Connection Status

> Monitor the WebSocket connection state and handle reconnection.

The CometChat SDK maintains a persistent WebSocket connection for real-time events. The `OnConnectionStateChanged` delegate lets you track the connection lifecycle and show appropriate UI (e.g., a "Reconnecting..." banner).

***

## Listen for Connection Changes

<Tabs>
  <Tab title="Blueprint">
    1. Get a reference to the **CometChat Subsystem**
    2. Drag off and search for **On Connection State Changed**
    3. Use **Bind Event** to connect it to a custom event
    4. The custom event receives an `ECometChatConnectionState` enum value
  </Tab>

  <Tab title="C++">
    ```cpp theme={null}
    void AMyActor::BeginPlay()
    {
        Super::BeginPlay();

        UCometChatSubsystem* Chat = GetGameInstance()->GetSubsystem<UCometChatSubsystem>();
        Chat->OnConnectionStateChanged.AddDynamic(this, &AMyActor::HandleConnection);
    }

    void AMyActor::HandleConnection(ECometChatConnectionState State)
    {
        switch (State)
        {
        case ECometChatConnectionState::Connected:
            UE_LOG(LogTemp, Log, TEXT("Connected — real-time events active"));
            HideConnectionBanner();
            break;

        case ECometChatConnectionState::Disconnected:
            UE_LOG(LogTemp, Warning, TEXT("Disconnected — no real-time events"));
            ShowConnectionBanner(TEXT("Connection lost"));
            break;

        case ECometChatConnectionState::Reconnecting:
            UE_LOG(LogTemp, Warning, TEXT("Reconnecting..."));
            ShowConnectionBanner(TEXT("Reconnecting..."));
            break;
        }
    }
    ```
  </Tab>
</Tabs>

***

## ECometChatConnectionState

| Value          | Description                                                                               |
| -------------- | ----------------------------------------------------------------------------------------- |
| `Connected`    | WebSocket is active. Real-time events (messages, presence, typing, receipts) are flowing. |
| `Disconnected` | WebSocket is closed. No real-time events will be received until reconnection.             |
| `Reconnecting` | The SDK detected a disconnect and is automatically attempting to reconnect.               |

***

## Reconnection Behavior

The SDK handles reconnection automatically:

1. When the WebSocket drops (network change, server timeout, etc.), the state moves to `Reconnecting`
2. The SDK retries with exponential backoff
3. On successful reconnection, the state moves back to `Connected`
4. If reconnection fails permanently, the state moves to `Disconnected`

<Tip>
  **UI pattern**: Show a subtle banner at the top of your chat screen when the state is `Disconnected` or `Reconnecting`. Hide it when `Connected` fires again. This gives players confidence that the chat system is working.
</Tip>

<Info>
  While disconnected, you can still call async nodes like **Get Messages Async** — those use HTTP requests, not the WebSocket. Only real-time push events are affected by the connection state.
</Info>

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Real-Time Events" icon="bolt" href="/sdk/unreal/real-time-events">
    See all five real-time delegates in one place.
  </Card>

  <Card title="API Reference" icon="book" href="/sdk/unreal/reference">
    Complete reference of all nodes, structs, and enums.
  </Card>
</CardGroup>
