Added close() method to stream classes.
[sockstream.git] / test / http_get.cpp
1 /**************************************************************************
2 **  (c) Copyright 2012, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : http-get.cpp
7 **      SYSTEM NAME    : Network and socket classes - test routine
8 **      VERSION NUMBER : 0.1
9 **
10 **  DESCRIPTION      :  Use a Socket object to download a page from an HTTP server.
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 "sockstream.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  : Nov 01, 2012
43 **=========================================================================
44 */
45
46 int main()
47 {
48    std::cout << "Finding www.andromeda.nl\n";
49    Host server(String("www.andromeda.nl"));
50    std::list<InternetAddress> iplist = server.FindAddress();
51
52    Service srv("http");
53    std::list<Port> portlist = srv.FindAddress();
54
55    IPSocketAddress serveraddress(iplist.front(), portlist.front());
56    StreamSocket s;
57
58    std::cout << "Connection result = " << s.Connect(serveraddress) << "\n";
59    sockstream http(s);
60
61    http << "GET / HTTP/1.1\n";
62    http << "Host: www.andromeda.nl\n" << std::endl;
63
64    String buf;
65    while (http >> buf)
66    {
67       std::cout << buf << "\n";
68    }
69
70 }
71