diff --git a/test/clsocket/EchoServer.cpp b/test/clsocket/EchoServer.cpp index 4173e5e6a..b5a3a0e21 100644 --- a/test/clsocket/EchoServer.cpp +++ b/test/clsocket/EchoServer.cpp @@ -13,7 +13,7 @@ int main(int argc, char **argv) //-------------------------------------------------------------------------- socket.Initialize(); - socket.Listen("127.0.0.1", 6789); + socket.Listen("localhost", 6667); while (true) { @@ -24,17 +24,34 @@ int main(int argc, char **argv) //---------------------------------------------------------------------- // Receive request from the client. //---------------------------------------------------------------------- - 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() ); - pClient->Close(); - } - + while (1) + { + //printf("try receive\n"); + bool receivedData = false; + + 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; } } diff --git a/test/clsocket/QueryDayTime.cpp b/test/clsocket/QueryDayTime.cpp index 46084256d..cb7381a64 100644 --- a/test/clsocket/QueryDayTime.cpp +++ b/test/clsocket/QueryDayTime.cpp @@ -19,7 +19,7 @@ int main(int argc, char **argv) // and received. //-------------------------------------------------------------------------- // 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. @@ -34,10 +34,13 @@ int main(int argc, char **argv) //---------------------------------------------------------------------- // Receive response from the server. //---------------------------------------------------------------------- - socket.Receive(len); - uint8* data = socket.GetData(); - memcpy(&time, data, len); - printf("%s\n", time); + int rec = socket.Receive(len); + if (rec) + { + uint8* data = socket.GetData(); + memcpy(&time, data, len); + printf("%s\n", time); + } //---------------------------------------------------------------------- // Close the connection.