#include #include #include "UDPTCPNetwork.h" #define DEFAULT_PORT 12345 int main (int argc, char **argv) { TCP tcpclient; char buffer[NET_BUFFERSIZE]; int i; int loop; #ifdef BUILD_WINDOWS char iobuffer[16]; setvbuf (stdout, iobuffer, _IONBF, 16); #endif // // connect to the server if (argc == 2) { if (tcpclient.Connect(argv[1], DEFAULT_PORT) != 1) { printf ("connect to: %s:%d\n",argv[1], DEFAULT_PORT); printf ("cloud not connect to server\n"); exit (1); } } else if (argc == 3) { printf ("connect to: %s:%d\n",argv[1], atoi(argv[2])); if (tcpclient.Connect(argv[1], argv[2]) != 1) { printf ("cloud not connect to server\n"); exit (1); } } else { printf ("\nplease use the ollowing commands:\n\n"); printf (" test-tcpclient destination\n"); printf (" test-tcpclient destination port\n"); return 1; } for (loop = 0; loop < 5; loop++) { // // send some data snprintf (buffer, NET_BUFFERSIZE, "nur ein kleiner Test."); printf ("client:send '%s' to the server.\n", buffer); if (tcpclient.Write(buffer, strlen (buffer)) != strlen (buffer)) { printf ("could not send all data.\n"); exit (1); } // // read some data (wait maximum 10x1000ms) for (i = 10; i > 0; i--) if (tcpclient.ReadTimeout(buffer, NET_BUFFERSIZE, 1000) > 0) { printf ("client:got '%s' from server.\n", buffer); break; } sleep (1); } // // close connection tcpclient.Close(); return 0; };