Skip to main content

cpp_connect_windows.cpp

/*****************************************************************************************
* cpp_connect_windows.cpp
*
* Note: See Tricryption Engine SDK for details on how to set the project environment.
*
******************************************************************************************/

#include <iostream>
#include "teconnection.h"
#include "teagent.h"
#include "teexception.h"
#include "teauthwinctx.h"

using namespace ERUCES;
using namespace std;


int main()
{
string strServerName = "localhost"; // server name
long lPort = 8888; // port number

try
{
auto_ptr<TEConnection> conn =
TEConnection::createInstance(TEConnection::SecureConnection);

// Open connection to the server for Windows user
auto_ptr<TEWinAuthenticationContext> ctx = TEWinAuthenticationContext::getInstance();

conn->open(strServerName, lPort, *ctx.operator->());

cout << "Connected to " << strServerName << " at " << lPort
<< " as Windows user\n" << endl;

// Close conneciton
conn->close();

cout << "Disconnected from server." << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}

return 0;
}