#include <iostream>
#include "teconnection.h"
#include "teagent.h"
#include "teexception.h"
#include "teauthwinctx.h"
#include "teauthuserctx.h"
using namespace ERUCES;
using namespace std;
int main()
{
string strServerName = "localhost";
long lPort = 8888;
string strUsername = "ls";
string strPassword = "password";
try
{
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
bool bUserContext = true;
if ( bUserContext )
{
auto_ptr<TEUserAuthenticationContext> ctx = TEUserAuthenticationContext::getInstance();
ctx->setUser(strUsername);
ctx->setPasswd(strPassword);
conn->open(strServerName, lPort, *ctx.operator->());
}
else
conn->open(strServerName, lPort, strUsername, strPassword);
cout << "Connected to " << strServerName << " at " << lPort
<< " as " << strUsername << "\n" << endl;
conn->close();
cout << "Disconnected from server." << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}