Optimal Location
Overview
The optimal location feature allows the VPN SDK to automatically select the best VPN server for your connection. This is ideal when you want to prioritize performance and let the system handle the routing decisions.
Sample Code
Here's a code snippet that demonstrates how to start a VPN session with an optimal server:
To retrieve information about the connected server, including the country, you can use the UnifiedSdk.getStatus
method. This method takes a Callback<SessionInfo>
object as a parameter, allowing you to handle the success and failure scenarios.
Here's a code snippet that shows how to get the country info for any kind of connection:
In the success
method of the callback, you will receive a SessionInfo
object containing information about the current VPN session. Retrieve the ConnectedServerInfo
object from the SessionInfo
object using the getConnectedServerInfo()
method. This object holds specific details about the connected server.
You can access the desired information from the ConnectedServerInfo
object. For example, you can retrieve the IP address of the connected server using serverInfo.getIp()
or the country using serverInfo.getCountry()
. Uncomment these lines in the provided code snippet to utilize the information.
Handle any failures in retrieving the session information by implementing the appropriate logic in the failure
method of the callback. This method receives a VpnException
object, which contains details about the encountered error.
Optimal Location vs. Virtual Locations
It is important to note that Optimal location and Virtual locations are two separate features that can be configured independently. They offer flexibility in managing VPN connections but serve different purposes.
Optimal location is a feature that automatically selects VPN nodes based on predefined rules. These rules are designed to provide the best possible connection based on factors such as geographic proximity, server load, and network performance. In some cases, users may not have control over the predefined logic used by the Optimal location feature.
Virtual locations, on the other hand, refer to a list of locations that are made available to users. This list may not necessarily include all the VPN nodes that are available through the Optimal location feature. Virtual locations allow users to manually select specific locations from the provided list.
Optimal location and Virtual locations are two powerful features in VPN configuration that provide flexibility and control over how users connect to VPN nodes. While Optimal location automatically selects the best node based on predefined rules, Virtual locations allow users to manually choose from a specific list of locations.
Example Scenario
To better understand the difference between Optimal location and Virtual locations, consider the following example:
Suppose a VPN service provider wants to configure their system so that all users in the United States are automatically connected to VPN nodes located in the closest major cities with available data centers. These cities might include San Francisco, Boston, New York, Seattle, and others. This is where the Optimal location feature comes into play, automatically selecting the best node based on the user's location.
In addition to the Optimal location feature, the service provider wants to give each user the option to manually select from two specific Virtual locations: New York and Boston. In this case, the Virtual locations list will only contain these two locations, even though the Optimal location feature might connect users to nodes in other cities.
It's important to note that the Optimal location feature might return nodes that belong to a location not included in the Virtual locations list.
Last updated
Was this helpful?