Fixed compiler for Java code generation (not heavily tested yet, but fixes include...
[iot2.git] / iotjava / iotrmi / C++ / IoTSocketClient.cpp
1 #include <iostream>
2 #include <string>
3 #include "IoTSocketClient.hpp"
4
5 using namespace std;
6
7 #define SIZE 10                  /* how many items per packet */
8 #define NUM_PACKS 3      /* number of times we'll do it */
9
10 int main(int argc, char *argv[])
11 {
12         char D[SIZE];
13
14         /* if no command line arguments passed, we'll default to 
15                 these two port number */
16         int port = 5010;
17         int rev = 0;
18         bool bResult = false;
19
20         fflush(NULL);
21         IoTSocketClient mylink(port, "127.0.0.1", rev, &bResult);
22
23         if (!bResult)
24         {
25                 printf("Failed to create Client object!\n");
26                 return 0;
27         }       
28
29         printf("Client, made connection...\n");
30         fflush(NULL);
31
32         /* put some dummy data in our arrays */
33
34         for (int i = 0; i < SIZE; i++)
35         {
36                 D[i] = i;
37         }
38
39         for (int i = 0; i < NUM_PACKS; i++)
40         {
41                 printf("Client, receiving bytes, iteration %d\n", i);
42                 fflush(NULL);
43                 mylink.receiveBytes(D);
44         }
45
46         char str[50];
47         char* str2;
48         fflush(NULL);
49         str2 = mylink.receiveBytes(str);
50         string s(str2);
51         cout << "Received text: " << s << endl;
52
53         printf("Client, closing connection...\n");
54         fflush(NULL);
55         mylink.close();
56
57         printf("Client, done...\n");
58         fflush(NULL);
59         return 0;
60 }