> For the complete documentation index, see [llms.txt](https://docs.sudoplatform.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sudoplatform.com/guides/virtual-private-network/manage-servers.md).

# Manage Servers

The **VPN SDK** provides a set of APIs to allow your users to manage the servers they choose to use to establish a VPN connection.

The `SudoVPNServer` object contains information about the server.

| Property        | Description                                                                |
| --------------- | -------------------------------------------------------------------------- |
| **country**     | The ISO 3166-1 Alpha-2 code of the country location.                       |
| **region**      | The region within the server country location (e.g. Florida).              |
| **coordinates** | Longitude and latitude coordinates of the server location.                 |
| **load**        | Server utilization which ranges from 0-100. 0 is low, whereas 100 is high. |
| **ipAddress**   | IP Address of the server.                                                  |

## Retrieving Servers

In order to establish a connection using the **VPN SDK**, a server is required. A list of available servers can be retrieved using the list servers API.

{% tabs %}
{% tab title="iOS" %}
There are two options for retrieving the list of servers.&#x20;

The user must be entitled in order to use the method `listServers(cachePolicy:)`. This method updates an internal cache which is required in order for a connection to complete, so there may be efficiency gains to using this method once the user has been confirmed to be entitled.&#x20;

Note that it is not mandatory for clients to call this method explicitly, however it will be called internally upon connection, if its internal cache has not already been populated.

Unentitled users must use the paginated method&#x20;

```
  listServers(
      countriesFilter: [],
      limit:,
      nextToken:,
      cachePolicy:)
```

to retrieve a list of servers, which can be filtered by an array of ISO3166 Alpha-2 two letter country codes. The `limit` and `nextToken` parameters are used to paginate through a potentially large list. This method uses an independent cache.

Each method will either return a list of valid servers to connect to, or an empty list if none are available. In the event of an error, a `SudoVPNError` will be thrown.

An example for unentitled users is:

```swift
var allServers: [SudoVPNServer] = []
do {
    var serverResult = 
        try await vpnClient.listServers(
            countriesFilter: ["AU"], 
            limit: 2000, 
            nextToken: nil)
    allServers.append(contentsOf: serverResult.items)
    // If you wish to handle all retrievals in a single task context
    while serverResult.nextToken != nil {
      serverResult = 
          try await vpnClient.listServers(
              countriesFilter:["AU"],
              limit: 2000,
              nextToken: serverResult.nextToken)
} catch {
    // Handle errors
}
```

And for entitled users:

```swift
var allServers: [SudoVPNServer] = []
do {
    allServers = 
        try await vpnClient.listServers(cachePolicy: .remoteOnly)
} catch {
    // Handle errors
}
```

{% endtab %}

{% tab title="Android" %}
A call to the `listServers` method provides a list of servers that can be used to establish a connection. An example implementation of retrieving the available servers is:

```kotlin
launch {
    try {
        val servers = withContext(Dispatchers.IO) {
            vpnClient.listServers()
        }
        // If no exception is thrown then the list of [servers] is returned.
    } catch (e: SudoVPNException) {
        // Handle/notify user of exception
    }
 }
```

The call to `listServers` will return the list of available servers. If an exception occurs, the `e.localizedMessage` can be presented to the user to notify them as to what caused the exception.
{% endtab %}

{% tab title="Typescript" %}
Clients should use the paginated method&#x20;

```typescript
  listServersByCountries(
      countriesFilter: string[],
      limit?: number,
      nextToken?: string:,
      cachePolicy?: CachePolicy)
```

to retrieve a list of servers, which can be filtered by an array of ISO3166 Alpha-2 two letter country codes. The `limit` and `nextToken` parameters are used to paginate through a potentially large list.&#x20;

This method will return a list of valid servers to connect to, or an empty list if none are available.&#x20;

For example:

```swift
let serverList: SudoVPNServer[] = []
try {
    let serverResult = 
        await vpnClient.listServersByCountries(
            countriesFilter: ['AU'], 
            limit: 200)
    serverList.push(...serverResult.items)
    // If you wish to handle all retrievals in a single task context
    while (serverResult.nextToken) {
      serverResult = 
          await vpnClient.listServersByCountries(
              countriesFilter: ['AU'],
              limit: 200,
              nextToken: serverResult.nextToken)
      serverList.push(...serverResult.items)
} catch {
    // Handle errors
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.sudoplatform.com/guides/virtual-private-network/manage-servers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
