more tcp testing

This commit is contained in:
Erwin Coumans
2017-02-20 09:52:59 -08:00
parent 970de9c4d7
commit c10dfe6a80
3 changed files with 37 additions and 28 deletions

View File

@@ -32,7 +32,7 @@ int main(int argc, char **argv)
if (pClient->Receive(MAX_PACKET)) if (pClient->Receive(MAX_PACKET))
{ {
char* msg = (char*) pClient->GetData(); char* msg = (char*) pClient->GetData();
//printf("received message [%s]\n",msg); printf("received message [%s]\n",msg);
//------------------------------------------------------------------ //------------------------------------------------------------------
// Send response to client and close connection to the client. // Send response to client and close connection to the client.
//------------------------------------------------------------------ //------------------------------------------------------------------

View File

@@ -19,35 +19,39 @@ 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("localhost", 6667)) if (socket.Open("192.168.86.196", 6667))
{ {
//---------------------------------------------------------------------- for (int i=0;i<100;i++)
// Send a requtest the server requesting the current time. {
//---------------------------------------------------------------------- //----------------------------------------------------------------------
char data[1024]; // Send a requtest the server requesting the current time.
sprintf(data,"%s","Hello!"); //----------------------------------------------------------------------
int len = strlen(data); char data[1024];
data[len]=0; sprintf(data,"%s %d","Hello",i);
len++; int len = strlen(data);
if (socket.Send((const uint8 *)data, len)) data[len]=0;
{ printf("Sending [%s]\n",data);
//---------------------------------------------------------------------- len++;
// Receive response from the server. if (socket.Send((const uint8 *)data, len))
//---------------------------------------------------------------------- {
int rec = socket.Receive(len); //----------------------------------------------------------------------
if (rec) // Receive response from the server.
{ //----------------------------------------------------------------------
uint8* data = socket.GetData(); int rec = socket.Receive(len);
memcpy(&time, data, len); if (rec)
printf("%s\n", time); {
} uint8* data = socket.GetData();
memcpy(&time, data, len);
printf("Received: [%s]\n", time);
}
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Close the connection. // Close the connection.
//---------------------------------------------------------------------- //----------------------------------------------------------------------
socket.Close(); socket.Close();
} }
}
return 1; return 1;

View File

@@ -13,8 +13,10 @@ project ("Test_clsocket_EchoServer")
links {"Ws2_32","Winmm"} links {"Ws2_32","Winmm"}
end end
if os.is("Linux") then if os.is("Linux") then
defines {"_LINUX"}
end end
if os.is("MacOSX") then if os.is("MacOSX") then
defines {"_DARWIN"}
end end
links {"clsocket"} links {"clsocket"}
@@ -38,10 +40,13 @@ project ("Test_clsocket_QueryDayTime")
defines { "WIN32" } defines { "WIN32" }
links {"Ws2_32","Winmm"} links {"Ws2_32","Winmm"}
end end
if os.is("Linux") then if os.is("Linux") then
end defines {"_LINUX"}
if os.is("MacOSX") then end
end if os.is("MacOSX") then
defines {"_DARWIN"}
end
links {"clsocket"} links {"clsocket"}