source: ada-examples/dumpwebpage/dumpwebpage.adb @ 04eee9f

ada-examples-4-10-branch
Last change on this file since 04eee9f was 09ee756, checked in by Joel Sherrill <joel.sherrill@…>, on 09/27/07 at 14:43:02

2007-09-27 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, Makefile, README, dumpwebpage.adb: New files.
  • Property mode set to 100644
File size: 1.3 KB
Line 
1--
2--  Dump Web Page GNAT Sockets Example
3--
4--  $Id$
5--
6
7with Ada.Text_IO;             use Ada.Text_IO;
8with GNAT.Sockets;            use GNAT.Sockets;
9with Ada.Strings.Unbounded;   use Ada.Strings.Unbounded;
10
11with Ada.Streams;
12use type Ada.Streams.Stream_Element_Count;
13
14
15procedure dumpWebPage is
16
17   Client  : Socket_Type;
18   Address : Sock_Addr_Type;
19   Channel : Stream_Access;
20
21   Send   : String := (1 => ASCII.CR, 2 => ASCII.LF);
22   Offset : Ada.Streams.Stream_Element_Count;
23   Data   : Ada.Streams.Stream_Element_Array (1 .. 256);
24
25   -- public IP of www.rtems.org as of 25 September 2007
26   -- Server : String :=  "216.186.189.3";
27   -- private OAR IP to test with
28   Server : String :=  "192.168.1.103";
29
30begin
31
32   Initialize;
33   Create_Socket (Client);
34   Address.Addr := Inet_Addr(Server);
35   Address.Port := 80;
36
37   Connect_Socket (Client, Address);
38   Channel := Stream (Client);
39
40   Put_Line( "GET / HTTP/1.1" & Send );
41   Put_Line( "Host: " & Server & Send );
42   String'Write (Channel, "GET / HTTP/1.1" & Send);
43   String'Write (Channel, "Host: " & Server & Send & Send);
44   loop
45      Ada.Streams.Read (Channel.All, Data, Offset);
46      exit when Offset = 0;
47      for I in 1 .. Offset loop
48         Ada.Text_IO.Put (Character'Val (Data (I)));
49      end loop;
50   end loop;
51
52end dumpWebPage;
Note: See TracBrowser for help on using the repository browser.