grass valley developers

Home > APIs > AppServer API > Examples > Connection and System Status > Basic Connection

The code below shows how to create a basic connection to a K2's AppService.

[C#] 
// create an AppServerMgr proxy object
AppServerMgrProxy appServerMgrProxy = new AppServerMgrProxy();

// set the host name of the K2 server
string host = "K2machinename";
appServerMgrProxy.SetHost(host);

// set the user credentials
string username = "username";
string password = "password";
string domain = "domain";
appServerMgrProxy.SetUserCredentials(username, password, domain, false);

// connect to the AppServerMgr
if ( !appServerMgrProxy.Connect() )
 Console.WriteLine("ERROR: Could not connect to AppService on " + host + ".");
else
 Console.WriteLine("Successfully connected to AppService.");

// ... do some work ...

// disconnect
appServerMgrProxy.Disconnect();
[C++] 
// Initialize the COM library
CoInitialize(NULL);

// create an AppServerMgr proxy object
IAppServerMgrProxyPtr spAppServerMgrProxy (__uuidof(AppServerMgrProxy));

// set the host name of the K2 server
_bstr_t bstrHost("K2machinename");
hr = spAppServerMgrProxy->SetHost(bstrHost);

// set the user credentials
_bstr_t bstrUsername("username");
_bstr_t bstrPassword("password");
_bstr_t bstrDomain("domain");
VARIANT_BOOL encrypted(FALSE);
hr = spAppServerMgrProxy->SetUserCredentials( bstrUsername, bstrPassword, 
 bstrDomain, encrypted);

// connect to the AppServerMgr
VARIANT_BOOL retVal;
hr = spAppServerMgrProxy->Connect(&retVal);
if ( !retVal )
 printf("ERROR - couldn't connect to the AppServerMgr\n");

// ... do some work ...

// disconnect
spAppServerMgrProxy->Disconnect(&retVal);