Ejemplo n.º 1
0
	dword ClientTask()
	{
		CScopedLock _lock;
		CTcpClient* pClient = NULL;
		CDataDoubleLinkedListT<CTcpClient>::Iterator it = _tcpclients.Begin();
				
		if ( it && (*it) )
		{
			pClient = *it;
			_tcpclients.Remove(it, EmptyDeleteFunc, NULL);
		}
		if ( !pClient )
			return 0;

		CStringBuffer sBuffer;

		wcout(_T("ClientTask"));
		try
		{
			CStringConstIterator itB;
			bool bExit = false;

			_lock.unlock();
			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			itB = sBuffer;
			itB.Find(_T("STOP\r\n"));
			if ( itB.IsBegin() )
				bExit = true;
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			pClient->CloseConnection();
			_lock.lock();
			pClient->release();
			_bExit = bExit;
		}
		catch ( CTcpClientException* ex )
		{
			COUT << ex->GetExceptionMessage() << endl;
			pClient->CloseConnection();
		}
		return 0;
	}
Ejemplo n.º 2
0
void TestTCPClientKeepAlive(CStringLiteral command)
{
	CTcpClient tcpClient;
	CStringBuffer sBuffer;
	CStringBuffer sBuffer0(__FILE__LINE__ _T("10: Testdaten (Client): 0123456789"));
	CStringBuffer sBuffer1(__FILE__LINE__ _T("20: Testdaten (Client): 0123456789"));
	CStringBuffer sBuffer2(__FILE__LINE__ _T("30: Testdaten (Client): 0123456789"));
	CStringBuffer sBuffer3(__FILE__LINE__ _T("40: Testdaten (Client): 0123456789"));
	CStringBuffer sBuffer4(__FILE__LINE__ _T("50: Testdaten (Client): 0123456789"));

	try
	{
		tcpClient.OpenConnection(_T("localhost"), DEFAULT_PORT);

		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer0);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer1);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer2);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer3);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		sBuffer.Clear();
		if ( !!command )
		{
			COUT << command << endl;
			sBuffer.AppendString(command);
			sBuffer.AppendString(_T("\r\n"));
		}
		sBuffer.AppendString(sBuffer4);
		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		tcpClient.CloseConnection();
	}
	catch ( CTcpClientException* ex )
	{
		COUT << ex->GetExceptionMessage() << endl;
		tcpClient.CloseConnection();
	}
}