File: QueryDayTime.cpp

package info (click to toggle)
bullet 2.87%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,272 kB
  • sloc: cpp: 204,241; ansic: 12,100; lisp: 12,017; python: 593; makefile: 136; sh: 8
file content (58 lines) | stat: -rw-r--r-- 2,407 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

#include <string.h>
#include "ActiveSocket.h"       // Include header for active socket object definition

int main(int argc, char **argv)
{
    CActiveSocket socket;       // Instantiate active socket object (defaults to TCP).
    char          time[50];

    memset(&time, 0, 50);

    //--------------------------------------------------------------------------
    // Initialize our socket object 
    //--------------------------------------------------------------------------
    socket.Initialize();

    //--------------------------------------------------------------------------
    // Create a connection to the time server so that data can be sent
    // and received.
    //--------------------------------------------------------------------------
//    if (socket.Open("time-C.timefreq.bldrdoc.gov", 13))
      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];
                    sprintf(data,"%s %d","Hello",i);
                    int len = strlen(data);
                    data[len]=0;
                    printf("Sending [%s]\n",data);
                    len++;
                    if (socket.Send((const uint8 *)data, len))
                    {
                        //----------------------------------------------------------------------
                        // Receive response from the server.
                        //----------------------------------------------------------------------
                        int rec = socket.Receive(len);
                        if (rec)
                        {
                                    uint8* data = socket.GetData();
                            memcpy(&time, data, len);
                            printf("Received: [%s]\n", time);
                        }
                    }
              }

            //----------------------------------------------------------------------
            // Close the connection.
            //----------------------------------------------------------------------
            socket.Close();
        }


    return 1;
}