Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/iot2
[iot2.git] / iotjava / iotrmi / C++ / IoTSocketServer.cpp
1 #include <iostream>
2 #include <string>
3 #include "IoTSocketServer.hpp"
4 #include "IoTRMIUtil.hpp"
5
6 using namespace std;
7
8
9 #define SIZE 10           /* how many items per packet */
10 #define NUM_PACKS 3   /* number of times we'll do it */
11
12 int main(int argc, char *argv[])
13 {
14         char D[SIZE];
15         bool bResult = false;
16
17         /* if no command line arguments passed, we'll default to 
18                 these two port number */
19         int port = 5010;
20         
21         fflush(NULL);
22
23         IoTSocketServer mylink(port, &bResult);
24         if (!bResult)
25         {
26                 printf("Failed to create Server object!\n");
27                 return 0;
28         }
29
30         /* put some dummy data in our arrays */
31         for (int i = 0,j = 100; i < SIZE; i++, j--)
32         {
33                 //D[i] = i;
34                 D[i] = j;
35         }
36         printf("Server, waiting for connection...\n");
37         fflush(NULL);
38         mylink.connect();
39         printf("Server, got a connection...\n");
40         fflush(NULL);
41
42         char bytes[24];
43         mylink.receiveBytes(bytes);
44         cout << "Received bytes: ";
45         IoTRMIUtil::printBytes(bytes, 24, false);
46
47         printf("Server, closing connection...\n");
48         fflush(NULL);
49         mylink.close();
50
51         printf("Server, done...\n");
52         fflush(NULL);
53         return 0;
54 }