Skip to main content

Basic SDK Functions

The functions below are essential to start, stop and communicate with the VPN SDK.

User Login Credentials Needed

You must have an active user account in order to create a minimum viable VPN product. Press the 'Add a New User' button at https://app.vpnwholesaler.com/users to create one.

At the bare minimum and considering that you already have login credentials for an active VPN account, you should implement the following functions and commands in order to create a minimum viable VPN product:

  1. Initialize SDK
  2. Set API domain
  3. Login
  4. Set VPN type
  5. Start VPN connection
  6. Stop VPN connection
  7. Finalize SDK

Initialize SDK​

Intializes the SDK with a callback and sets necessary path to OpenVPN binary.

Login required: No Code: InitOVSCore Input:

int InitOVSCore(OVSNotifyCB callback, Activity context)

Input Parameters:

Callback - reference to callback function with following signature:

void (char* notify_data)

Response:

int - returns 0 if SDK was intialized sucessfully and other value in case of failure

Code sample:

It is recommended to implement event listener in your Activity class in the following way:

Android Code Sample - Event Listener

public class SDKWrapper implements VPNSDK.CommandNotifyCB {
@Override
public void onNotify(int notification, int error, Object data) {
switch (notification) {
// Following is called when VPN status was changed
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECT_FAILED:
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_ABNOMARLY_DISCONNECTED:
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_DISCONNECTED: {
// Do something when VPN was disconnected
break;
}
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECTING: {
// Do something when VPN was started to connect
break;
}
case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_VPN_CONNECTED: {
// Do something when VPN was connected
break;
}
// Following is called when we request VPN status explicitly

case VPNSDK.OVS_NOTIFY_CODES.OVS_NOTIFY_GET_STATUS: {
int state = (Integer)((Map)data).get("VPN_Status");
switch (state) {
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_DISCONNECTED:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_ABNORMALLY_DISCONNECTED:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONN_FAILED: {
// Do something when VPN was disconnected
break;
}
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_ASSIGNIP:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_GETCONFIG:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_AUTH:
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONNECTING: {
// Do something when VPN was started to connect
break;
}
case VPNSDK.VPN_NOTIFY_STATUS.VPN_NOTIFY_CONNECTED: {
// Do something when VPN was connected
break;
}
}

break;
}
}
}
}

Then you can initialize the SDK using the following code:

SDKWrapper wrapper = new SDKWrapper();
VPNSDK.InitOVSCore(wrapper, this);

Finalize SDK​

Unloads SDK and finalizes all running threads. It is necessary to call this method before exit to avoid leaks.

Login required: No Code: FinalizeOVSCore() Input: None Response: None Code sample:

VPNSDK.FinalizeOVSCore();

Send command​

Asynchronously sends command to SDK. Command result will be returned by calling the callback that was specified on initialization.

All operations in SDK are called asynchronously, and therefore a single callback is used to receive responses from all SDK functions. All responses are encoded as JSON and described in the relevant sections.

Login required: Depending on the command CmdProc Code: CmdProc(szCmdData) Input:

{
"cmd": int,
"data: { Command parameters }
}

Response: Generally, responses carry the following JSON structure:

{
"code": integer
"err": integer
"data": { object }
}

Where:

code - the invoked command's notification event. err - error code. data - response based on the notification code.