Connecting to Specific Locations using GetLocations
To connect to a specific location, you can use either the VpnCustomLocations property of the GetLocationsResponse. Here's how you can do it:
var selectedCustomLocation =getLocationsResponse.VpnCustomLocations[0];
The Locations[0] element points to the same location as VpnCustomLocations[0]. The Locations is useful for finding a location to display based on the connection's location index.
Only the VpnCustomLocations is used for establishing the connection. The Locations can be useful for displaying the connection location in the user interface.
Searching for a Specific Location
If you want to connect to a location based on its name, you can search through the VpnCustomLocations list:
var locationName ="YOUR_SELECTED_LOCATION";var selectedLocation =getLocationsResponse.VpnCustomLocations .FirstOrDefault(loc =>loc.Location== locationName);if (selectedLocation !=null){ // Do something}else{Console.WriteLine("Location not found");}
Choosing Between GetNodes and GetLocations
While GetNodes provides a broader list of countries, GetLocations offers more detailed information that can be useful for advanced features. Choose the appropriate method based on your specific requirements and the level of detail you need to present to your users.
Function
When To Use
GetNodes
You only need country-level information
You want to display a list of countries in your UI
You need a broader range of connection options
GetLocations
You need more detailed location information (potentially including cities)
You're implementing multi-hop, custom DNS, or VPN profiles features
You want to display both country and city information in your UI
For more information, please refer to the API documentation available at:
You have the ability to customize and apply the configuration template for the hydra protocol. To learn about the specific customization options available and to obtain a customized configuration please contact your sales representative.
Once you receive the configuration template you need to use the parameter HydraConfigTemplatein the StartVpnRequest.
With "StartVpnRequest" you can send "WaitConnected" flag which means:
True - "StartVpn" method will wait until the tunnel will be connected before sending the response. This value is for backward compatibility with previous versions.
Null/False (default) - "StartVpn" method will send response after connection will be initiated and later it can be canceled by "StopVpn" request. The connection status or error will be received through the 'StateChanged' event.
GetConnectionState
Gets current VPN connection state based on the VPN connection state stored in Unified SDK service.
var sdk =newSDK();var stateResponse =awaitsdk.GetConnectionStateAsync().ConfigureAwait(false);if (stateResponse.Result.Equals(ResponseResult.Ok)){Console.WriteLine(stateResponse.OperationalState);}
The VPN connection state represents an Enum:
TunnelIdle - either doing nothing or trying to reconnect over and over again with no luck.
TunnelConnecting - establishing the connection.
TunnelConnected - connected to one or more servers and ready to process diverted network traffic.
TunnelDisconnected - disconnected from all the connected servers (if any) and not diverting network traffic.
GetConnectedServerInfo
Returns the connected server information. It will be one of the servers received from GetCredentials response. Tunnel should be in the TunnelConnected state, otherwise it will return an error.
var sdk =newSDK();var serverResponse =awaitsdk.GetConnectedServerInfoAsync().ConfigureAwait(false);if (serverResponse.Result.Equals(ResponseResult.Ok)){Console.Write(serverResponse.IPv4);Console.Write('-');Console.Write(serverResponse.Country);Console.Write('-');Console.WriteLine(serverResponse.Name);}
StopVpn
Stops VPN.
var sdk =newSDK();var stopVpnRequest =newStopVpnRequest{ KeepKillSwitchEnabled =false,};var stopVpnResponse =awaitsdk.StopVpnAsync(stopVpnRequest).ConfigureAwait(false);Console.WriteLine(stopVpnResponse.ExitCode);