# Reconnection strategy

## Overview

See [Reconnection strategy](/paas/sdk/unified-vpn-sdk/features/reconnection-strategy.md)

## Enabling Automatic Reconnection

Automatic reconnection is enabled by default. To explicitly enable it (for example, after previously disabling it), you can use the following method:

```kotlin
import unified.vpn.sdk.*

UnifiedSdk.setReconnectionEnabled(true)
```

By calling `setReconnectionEnabled(true)`, the SDK will resume handling network switches and transport errors automatically.

## Disabling Automatic Reconnection

To disable the automatic reconnection behavior, you can use the following method:

```kotlin
import unified.vpn.sdk.*

UnifiedSdk.setReconnectionEnabled(false)
```

By calling `setReconnectionEnabled(false)`, the SDK will not attempt to reconnect automatically when network switches occur or transport errors happen. You will need to handle reconnection manually in your application logic.

## Default Reconnection Behavior

By default, the SDK will automatically handle network reconnection when the user switches between networks. The SDK's behavior in different scenarios is as follows:

### VPN ON and Network Connection Disabled

* If VPN is ON and the user disables the network connection, the SDK transfers to the PAUSED state.
* After the network connection is re-enabled, the SDK automatically connects to the last successful configuration.

### Transport Error During Connection

* If a transport error occurs during connection, the SDK will attempt to reconnect automatically.
* However, there are certain exceptions where automatic reconnection will not occur:

| Error Code             | Description                                                                                     |
| ---------------------- | ----------------------------------------------------------------------------------------------- |
| `CODE_NOT_AUTHORIZED`  | The user is not authorized. In this case, you need to call `HydraSdk.login` to re-authenticate. |
| `CODE_SESSIONS_EXCEED` | The session limit is reached in accordance with the Terms of Service (ToS).                     |
| `CODE_DEVICES_EXCEED`  | The devices limit is reached in accordance with the ToS.                                        |
| `CODE_OAUTH_ERROR`     | An authentication error occurred on the OAuth server.                                           |
| `CODE_TRAFFIC_EXCEED`  | The traffic limit is exceeded in accordance with the ToS.                                       |
| `USER_SUSPENDED`       | The user account is suspended.                                                                  |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pango.gitbook.io/paas/sdk/vpn-sdk-for-android/features/reconnection-strategy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
