|
|
@ -10,6 +10,7 @@ int main (int argc, char **argv) {
|
|
|
|
TCP tcpclient;
|
|
|
|
TCP tcpclient;
|
|
|
|
char buffer[NET_BUFFERSIZE];
|
|
|
|
char buffer[NET_BUFFERSIZE];
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
int loop;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef BUILD_WINDOWS
|
|
|
|
#ifdef BUILD_WINDOWS
|
|
|
|
char iobuffer[16];
|
|
|
|
char iobuffer[16];
|
|
|
@ -20,13 +21,13 @@ int main (int argc, char **argv) {
|
|
|
|
// connect to the server
|
|
|
|
// connect to the server
|
|
|
|
if (argc == 2) {
|
|
|
|
if (argc == 2) {
|
|
|
|
if (tcpclient.Connect(argv[1], DEFAULT_PORT) != 1) {
|
|
|
|
if (tcpclient.Connect(argv[1], DEFAULT_PORT) != 1) {
|
|
|
|
printf ("connect to: %s:%s\n",argv[1], DEFAULT_PORT);
|
|
|
|
printf ("connect to: %s:%d\n",argv[1], DEFAULT_PORT);
|
|
|
|
printf ("cloud not connect to server\n");
|
|
|
|
printf ("cloud not connect to server\n");
|
|
|
|
exit (1);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (argc == 3) {
|
|
|
|
else if (argc == 3) {
|
|
|
|
printf ("connect to: %s:%s\n",argv[1], atoi(argv[2]));
|
|
|
|
printf ("connect to: %s:%d\n",argv[1], atoi(argv[2]));
|
|
|
|
if (tcpclient.Connect(argv[1], argv[2]) != 1) {
|
|
|
|
if (tcpclient.Connect(argv[1], argv[2]) != 1) {
|
|
|
|
printf ("cloud not connect to server\n");
|
|
|
|
printf ("cloud not connect to server\n");
|
|
|
|
exit (1);
|
|
|
|
exit (1);
|
|
|
@ -39,23 +40,26 @@ int main (int argc, char **argv) {
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
for (loop = 0; loop < 5; loop++) {
|
|
|
|
// send some data
|
|
|
|
//
|
|
|
|
snprintf (buffer, NET_BUFFERSIZE, "nur ein kleiner Test.");
|
|
|
|
// send some data
|
|
|
|
printf ("client:send '%s' to the server.\n", buffer);
|
|
|
|
snprintf (buffer, NET_BUFFERSIZE, "nur ein kleiner Test.");
|
|
|
|
if (tcpclient.Write(buffer, strlen (buffer)) != strlen (buffer)) {
|
|
|
|
printf ("client:send '%s' to the server.\n", buffer);
|
|
|
|
printf ("could not send all data.\n");
|
|
|
|
if (tcpclient.Write(buffer, strlen (buffer)) != strlen (buffer)) {
|
|
|
|
exit (1);
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// close connection
|
|
|
|
tcpclient.Close();
|
|
|
|
tcpclient.Close();
|
|
|
|