> ## 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 CometChat WebSocket connection status in Flutter apps with callbacks for connecting, connected, disconnected, and errors.

CometChat SDK provides you with a mechanism to get real-time status of the connection to CometChat web-socket servers. To achieve this you need to use the `ConnectionListener` class provided by the CometChat SDK

Connection Status provides you with the below 3 methods to get the status of the connection to CometChat web-socket servers:

| Delegate Method    | Information                                                                                                                                      |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| onConnecting       | This method is triggered when CometChat SDK is trying to establish a connection to the web-socket server.                                        |
| onConnected        | This method is called when CometChat SDK has successfully established a connection and now is connected.                                         |
| onDisconnected     | This method is called when the CometChat SDK gets disconnected due to any issue while maintaining the connection like network fluctuations, etc. |
| onFeatureThrottled | CometChat automatically toggles off certain features to prevent performance loss for end-users under various circumstances                       |
| onConnectionError  | This method is called when the CometChat SDK gets error due to any issue while maintaining the connection like network fluctuations, etc.        |

Once the connection is broken, the disconnected callback is triggered, the SDK automatically tries to establish the connection again, thus going into the connecting state and triggering the `connecting` method. Once the attempt to connect is successful, the `connected` method is triggered thus letting the developer know that the connection is established and is active.

In order to use the ConnectionListeners, you need to add the ConnectionListeners using the `addConnectionListener` method provided by the SDK. You can add multiple listeners as shown below. Just make sure you add listeners with unique IDs.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    class Class_Name  with ConnectionListener {
    //1. Register Connection listener
    //CometChat.addConnctionListener("listenerId", this);

    //2. Ovveride the ConnectionListener methods
    @override
    void onConnected() {
      // TODO: implement onConnected
    }

    @override
    void onConnecting() {
      // TODO: implement onConnecting
    }

    @override
    void onDisconnected() {
      // TODO: implement onDisconnected
    }

    @override
    void onFeatureThrottled() {
      // TODO: implement onFeatureThrottled
    }

    @override
    void onConnectionError(CometChatException error) {
      // TODO: implement onFeatureThrottled
    }

    }
    ```
  </Tab>
</Tabs>

You can also get the current connection status by using `getConnectionStatus` property provided by CometChat SDK

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    String connectionStatus = CometChat.getConnectionStatus();
    ```
  </Tab>
</Tabs>

The above method will return either of the below 3 values:

1. `CometChatWSState.connected` (connected);
2. `CometChatWSState.connecting`(connecting)
3. `CometChatWSState.disconnected`(disconnected)
4. `CometChatWSState.featureThrottled`(featureThrottled)

<Note>
  Know more about CometChat SDK connection behaviour [click here](/sdk/flutter/connection-behaviour)
</Note>
