First commit of release 0.1
[sockstream.git] / test / iptest.cpp
1 /**************************************************************************
2 **  (c) Copyright 2012, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : iptest.cpp
7 **      SYSTEM NAME    : Network and socket classes - test routine
8 **      VERSION NUMBER : 0.1
9 **
10 **  DESCRIPTION      :  Internet address classes tests
11 **
12 **  EXPORTED OBJECTS : 
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    :
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Mar 02, 2012
20 **      LAST UPDATE     : Mar 05, 2012
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24
25 #include "host.h"
26 #include "service.h"
27 #include "socket.h"
28
29
30 /*=========================================================================
31 **  NAME           : main
32 **  SYNOPSIS       :
33 **  PARAMETERS     :
34 **  RETURN VALUE   : None
35 **
36 **  DESCRIPTION    : 
37 **
38 **  VARS USED      :
39 **  VARS CHANGED   :
40 **  FUNCTIONS USED :
41 **  SEE ALSO       :
42 **  LAST MODIFIED  : Mar 05, 2012
43 **=========================================================================
44 */
45
46 int main()
47 {
48    std::cout << "IP address test\n";
49
50    InternetAddress ip("1:0:0:a::1");
51
52    std::cout << String(ip) << "\n";
53
54    std::cout << "Finding www.noortict.nl\n";
55    Host server(String("www.noortict.nl"));
56    std::list<InternetAddress> iplist = server.FindAddress();
57    std::list<InternetAddress>::iterator ipaddress;
58    for (ipaddress = iplist.begin(); ipaddress != iplist.end(); ipaddress++)
59    {
60       std::cout << "  IP address " << String(*ipaddress) << "\n";
61    }
62
63    Service srv("http");
64    std::list<Port> portlist = srv.FindAddress();
65    std::list<Port>::iterator port;
66    for (port = portlist.begin(); port != portlist.end(); port++)
67    {
68       std::cout << "  Port " << port->get_port() << ", socket type " << port->get_sockettype() << "\n";
69    }
70
71    IPSocketAddress serveraddress(iplist.front(), portlist.front());
72    StreamSocket s;
73
74    std::cout << "Connection result = " << s.Connect(serveraddress) << "\n";
75    s.Write("GET / HTTP/1.1\n", 15);
76    s.Write("Host: www.noortict.nl\n\n", 23);
77
78    char buf[1000];
79    int  len;
80    do
81    {
82       len = s.Read(buf, 1000);
83       buf[len] = '\0';
84       std::cout << "LEN = " << len << "\n" << buf << "\n";
85    }
86    while (len > 0);
87
88 }
89