ITANABufferServerTest.cpp 1.64 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>

#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Connections/VistaConnectionIP.h>
#include <VistaInterProcComm/IPNet/VistaTCPServer.h>
#include <VistaInterProcComm/IPNet/VistaTCPSocket.h>
//#include <VistaBase/VistaTimeUtils.h>
#include <VistaInterProcComm/IPNet/VistaIPAddress.h>

#include <ITAStringUtils.h>

int main( int argc, char** argv )
{
	std::string sServerName = "localhost";
	int iServerPort = 12343;

	std::cout << "Setting up ITANA server command channel on '" << sServerName << ":" << iServerPort << "'" << std::endl;
	VistaTCPServer oNAServer( sServerName, iServerPort, 1 );

	std::cout << "Waiting for connection" << std::endl;
	VistaTCPSocket* pSocket = oNAServer.GetNextClient();

	if( oNAServer.GetIsValid() == false )
	{
		std::cerr << "Could not start server" << std::endl;
		return 255;
	}

	std::cout << "Waiting for result channel port" << std::endl;
	unsigned long l = pSocket->WaitForIncomingData( 0 );

	if( l == 8 )
	{
		unsigned long iRequestedResultChannelPort;
		pSocket->ReceiveRaw( &iRequestedResultChannelPort, 8 );

		std::string sRemoteAddress;
		VistaSocketAddress sAddr;
		pSocket->GetPeerSockName( sAddr );
		sAddr.GetIPAddress().GetAddressString( sRemoteAddress );

		VistaConnectionIP oConnection( VistaConnectionIP::CT_TCP, sRemoteAddress, iRequestedResultChannelPort );

		bool bAck = oConnection.GetIsConnected();
		oConnection.Send( &bAck, sizeof( bool ) );
		oConnection.WaitForSendFinish( 0 );

		std::cout << "Result channel connection successfully established" << std::endl;

		oConnection.Close( false );
	}

	pSocket->CloseSocket();

	return 0;
}