Manage Connection

Provides the essentials to allow your users to connect and disconnect from a server and view their connection status.

The VPN SDK provides a set of APIs to allow your users to establish and teardown a VPN connection with a server.

Establish a Connection

A connection to a server is established by calling the connect to server API using a server selected from the list servers API call.

In order to establish a connection, a SudoVPNServer is required.

Connection Configuration

Connection configuration is decided at the time of calling the connect API. It is up to you to build up a SudoVPNConfiguration object.




The SudoVPNServer that the client will/is connected to.


The SudoVPNProtocol that the client will/is using to connect to the VPN.

When the disconnect API is called, the configured server will be set back to undefined.

Both server and protocolType can be left as undefined. In the case that server is left undefined, the best server will be attempted to connect to, using the user's current geographical location. If protocolType is left undefined, the default protocol (IPSec (IKEv2) on mobile) will be used.

Protocol Types

When connecting to a VPN, a couple of different Protocol types are available. Depending on the platform, only a subset of these types may be supported.

In a scenario where network is lost whilst connected to an IPSec (IKEv2) or UDP protocol, the VPN tunnel will remain open. This allows the connection to stay open if there are changes in the network (i.e. moving from Wi-Fi to Mobile Data).

In order to see which protocols are currently available via the client, use the supportedProtocols() method. This method returns the list of supported protocols mentioned above currently available to the device calling the method.

An example implementation is:

let supportedProtocols = vpnClient.supportedProtocols()
/// `supportedProtocols` contains an array of the protocols that can be used.

Connect to the VPN

To connect to the VPN, use the connect(withConfiguration:completion:) method. The completion will be called either when the connection process has successfully begun, or an error occurred while attempting to do so.

If configuration is nil, the best server, and default protocol type will be used.

An example implementation of calling the connect method is:

vpnClient.connect { result in
    switch result {
    case let .failure(cause):
        /// Handle/notify user of error.
    case .success:
        /// Successfully begun connection. 

To watch for connection state events to see when the client has successfully connected (or failed to connect), see Connection Events.

Disconnect from an Established Connection

Once already connected, a user may want to deliberately disconnect, or close the connection as part of a process.

To disconnect from an already established connection, use the disconnect(completion:) method.

An example implementation of calling the disconnect method is:

vpnClient.disconnect { result in
    switch result {
    case let .failure(cause):
        /// Handle/notify user of error.
    case .success:
        /// Successfully disconnected. 

To watch for connection state events to see when the client has successfully disconnected (or failed to disconnect), see Connection Events.

Last updated