How do I connect to a Server?
Connecting to your Server is the first thing that must be done before you can use any other SDK functionality.
In this example we:
- Create the Server object
- Create the ServerAddresses object
- Call Connect() on the Server object
- Check the value returned by the call to Connect() to ensure that we have successfully connected
- Display an appropriate error message if the Connect() call failed
- Disconnect from the Server object
For complete examples refer to the sample applications that come with the DecoderSDK.
Example
// Create the server object
server = new Server(L"Windows-General-Sample-App", L"os:Windows 7 x64, app:Windows General Sample App, app_ver:0.1.0");
// NOTE: 9300 is the default port for EdgeVis Server
ServerAddresses knownServer(L"my.server.com", 9300, false);
ServerAddresses availableServers;
//Connect to the server
OpResult result = server->Connect(knownServer,L"username",L"password", L"", availableServers, ConnectionStrategy::DEFAULT);
if(result == OR_Success)
{
wcout << L"Connected to server!" << endl;
// register to receive IServerListener callbacks
server->RegisterListener(this);
} else {
//The connection failed Check the reult for error message
wcout << L"Connection failed!" << endl;
}
server->Disconnect();
private const string APP_NAME = "Windows-csharp-General-Sample-App";
private const string APP_METADATA = "os:Windows 7 x64, app:Windows CSharp General Sample App, app_ver:1.0.0";
private const string SERVER = "localhost";
private const string ENCODER = "demo-enc";
private const string USERNAME = "Administrator";
private const string PASSWORD = "password";
private const int PORT = 9300;
private const string NEW_PASSWORD = "";
// NOTE: 9300 is the default port for EdgeVis Server
ServerAddresses knowServer = new ServerAddresses(SERVER, PORT, false);
ServerAddresses availableServers = new ServerAddresses();
Server _server = new Server(APP_NAME, APP_METADATA);
// Register to receive IServerListener callbacks
ServerListener _serverListener = new ServerListener();
_server.RegisterListener(_serverListener);
// Connect to our server!
OpResult result = _server.Connect(knowServer, USERNAME, PASSWORD, NEW_PASSWORD, availableServers, ConnectionStrategy.DEFAULT, ServerConnectInfo.SCI_ASPECT_CORRECT);
if (result == OpResult.OR_Success)
{
//Connected
Console.WriteLine("Connected to the server!");
} else {
//The connection failed Check the reult for error message
Console.WriteLine("Connection failed!");
}
// Disconnect from the server
_server.Disconnect();
private final String APP_NAME = "Android-General-Sample-App";
private final String APP_METADATA = "os:Android, app:Android General Sample App, app_ver:1.0.0";
private final String SERVER = "your.server.com";
private final String ENCODER = "AnEncoderName";
private final String USERNAME = "yourUserName";
private final String PASSWORD = "yourPassword";
// NOTE: 9300 is the default port for EdgeVis Server
ServerAddresses knownServer = new ServerAddresses(SERVER, 9300, false);
ServerAddresses availableServers = new ServerAddresses(SERVER, 9300, false);
server = new Server(APP_NAME, APP_METADATA);
// Register to receive IServerListener callbacks
serverListener = new SDKServerListener();
server.RegisterListener(serverListener);
// Connect to our server!
OpResult connect = server.Connect(knownServer,USERNAME,PASSWORD,NEW_PASSWORD,availableServers, ConnectionStrategy.DEFAULT, ServerConnectInfo.SCI_NONE);
if(connect != null && connect.toString().equals(OR_Success.toString())){
Log.i(TAG, "Connected to server");
} else {
Log.i(TAG, "Connection failed");
}
server.Disconnect();
server = null;