tcp echo/query test setup

This commit is contained in:
Erwin Coumans
2017-02-20 09:34:00 -08:00
parent 3e94840340
commit 970de9c4d7
2 changed files with 37 additions and 17 deletions

View File

@@ -13,7 +13,7 @@ int main(int argc, char **argv)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
socket.Initialize(); socket.Initialize();
socket.Listen("127.0.0.1", 6789); socket.Listen("localhost", 6667);
while (true) while (true)
{ {
@@ -24,17 +24,34 @@ int main(int argc, char **argv)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Receive request from the client. // Receive request from the client.
//---------------------------------------------------------------------- //----------------------------------------------------------------------
if (pClient->Receive(MAX_PACKET)) while (1)
{ {
char* msg = (char*) pClient->GetData(); //printf("try receive\n");
printf("received message [%s]\n",msg); bool receivedData = false;
//------------------------------------------------------------------
// Send response to client and close connection to the client.
//------------------------------------------------------------------
pClient->Send( pClient->GetData(), pClient->GetBytesReceived() );
pClient->Close();
}
if (pClient->Receive(MAX_PACKET))
{
char* msg = (char*) pClient->GetData();
//printf("received message [%s]\n",msg);
//------------------------------------------------------------------
// Send response to client and close connection to the client.
//------------------------------------------------------------------
pClient->Send( pClient->GetData(), pClient->GetBytesReceived() );
receivedData = true;
if (strncmp(msg,"stop",4)==0)
{
printf("Stop request received\n");
break;
}
}
if (!receivedData)
{
printf("Didn't receive data.\n");
break;
}
}
printf("Disconnecting client.\n");
pClient->Close();
delete pClient; delete pClient;
} }
} }

View File

@@ -19,7 +19,7 @@ int main(int argc, char **argv)
// and received. // and received.
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// if (socket.Open("time-C.timefreq.bldrdoc.gov", 13)) // if (socket.Open("time-C.timefreq.bldrdoc.gov", 13))
if (socket.Open("127.0.0.1", 6789)) if (socket.Open("localhost", 6667))
{ {
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Send a requtest the server requesting the current time. // Send a requtest the server requesting the current time.
@@ -34,10 +34,13 @@ int main(int argc, char **argv)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Receive response from the server. // Receive response from the server.
//---------------------------------------------------------------------- //----------------------------------------------------------------------
socket.Receive(len); int rec = socket.Receive(len);
uint8* data = socket.GetData(); if (rec)
memcpy(&time, data, len); {
printf("%s\n", time); uint8* data = socket.GetData();
memcpy(&time, data, len);
printf("%s\n", time);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Close the connection. // Close the connection.