> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-agent-native-development.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Connection Status

> Monitor real-time WebSocket connection status to CometChat servers in the Android SDK with listeners and reconnect handling.

<Accordion title="AI Integration Quick Reference">
  ```kotlin theme={null}
  // Add connection listener
  CometChat.addConnectionListener("LISTENER_ID", object : ConnectionListener {
      override fun onConnected() { /* Connection established */ }
      override fun onConnecting() { /* Attempting to connect */ }
      override fun onDisconnected() { /* Connection lost */ }
      override fun onFeatureThrottled() { /* Features throttled */ }
      override fun onError(e: CometChatException) { /* Connection error */ }
  })

  // Get current connection status
  val status = CometChat.getConnectionStatus()
  // Returns: WS_STATE_CONNECTED, WS_STATE_CONNECTING, WS_STATE_DISCONNECTED, or WS_STATE_FEATURE_THROTTLED

  // Remove listener
  CometChat.removeConnectionListener("LISTENER_ID")
  ```
</Accordion>

Use `ConnectionListener` to monitor real-time WebSocket connection state. The SDK automatically attempts to reconnect when disconnected.

| Callback | Description |
| - | - |
| `onConnecting` | SDK is attempting to establish a WebSocket connection |
| `onConnected` | Connection successfully established |
| `onDisconnected` | Connection lost (network fluctuation, etc.) |
| `onFeatureThrottled` | CometChat toggled off certain features to prevent performance loss |

Error callbacks receive a [`CometChatException`](/sdk/reference/auxiliary#cometchatexception) with details about the connection failure.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChat.addConnectionListener("UNIQUE_LISTENER_ID", new CometChat.ConnectionListener() {
      @Override
        public void onConnected() {
        Log.i(TAG, "onConnected: ");
      }
      
      @Override
        public void onConnecting() {
        Log.i(TAG, "onConnecting: ");
      }

      @Override
        public void onDisconnected() {
        Log.i(TAG, "onDiconnected: ");
      }
      
      @Override
        public void onFeatureThrottled() {
        Log.i(TAG, "onFeatureThrottled: ");
      }
      
      @Override
        public void onConnectionError(CometChatException e) {
        Log.i(TAG, "onConnectionError: ");
      }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    CometChat.addConnectionListener("UNIQUE_LISTENER_ID", object : ConnectionListener {
      override fun onConnected() {
        Log.i(TAG, "onConnected: ")
      }

      override fun onConnecting() {
        Log.i(TAG, "onConnecting: ")
      }

      override fun onDisconnected() {
        Log.i(TAG, "onDiconnected: ")
      }

      override fun onFeatureThrottled() {
        Log.i(TAG, "onFeatureThrottled: ")
      }
      
      override fun onError(e: CometChatException) {
        Log.i(TAG, "onError: ")
      }
    }) 
    ```
  </Tab>
</Tabs>

## Get Current Status

Use `getConnectionStatus()` to check the current connection state at any time:

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

  <Tab title="Kotlin">
    ```kotlin theme={null}
    val connectionStatus = CometChat.getConnectionStatus() 
    ```
  </Tab>
</Tabs>

Returns one of:

| Value | Description |
| - | - |
| `CometChatConstants.WS_STATE_CONNECTED` | Active connection |
| `CometChatConstants.WS_STATE_CONNECTING` | Attempting to connect |
| `CometChatConstants.WS_STATE_DISCONNECTED` | No connection |
| `CometChatConstants.WS_STATE_FEATURE_THROTTLED` | Feature throttled |

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

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Connection Behaviour" icon="network-wired" href="/sdk/android/connection-behaviour">
    Learn about SDK connection behavior and reconnection logic
  </Card>

  <Card title="Setup" icon="gear" href="/sdk/android/setup">
    Initialize the SDK and establish connection
  </Card>

  <Card title="User Presence" icon="circle-dot" href="/sdk/android/user-presence">
    Track user online/offline status
  </Card>

  <Card title="Real-Time Listeners" icon="bell" href="/sdk/android/real-time-listeners">
    Register listeners for messages, users, groups, and calls
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.