Skip to main content

Go Online

The following code sample illustrates how to take a remote engine on line and into communication with a key service.


Code Sample

See the C++ environment settings for details on setting the project environment.


<cpp_adminlocal_goonline.cpp>
/*****************************************************************************************
*
* cpp_adminlocal_goonline.cpp
*
*
******************************************************************************************/

#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teadmin_local.h"

using namespace ERUCES;
using namespace std;

int main()
{
string strServer = "localhost"; // this is the remote engine
long nPort = 5050; // this is the local admin port.
string strUser = "ls"; // this is a normal TE user, not necessarily a TE admin user.
string strPswd = "password";

try
{
// Connect to local server
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);

auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strUser);
ctx->setPasswd(strPswd);
ctx->setMode(1); // set to 1 if going to call goOnLine().
conn->open(strServer, nPort, *ctx.operator->());

cout << "Connected to " << strServer << " as " << strUser
<< " at port " << nPort << endl;

// Local administrator
TEAdminLocal adminlocal;
adminlocal.attachConnection(conn.operator->());

// Go online
adminlocal.goOnLine();

cout << "Client is now Online:" << endl;

adminlocal.detachConnection();

// Disconnect from local server
conn->close();
cout << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}

return 0;
}
Output
Connected to localhost as ls at port 5050
Client is now Online:
Disconnected from localhost