blob: c7cc82b6bf0791f1643e4377d57dbb94f444693f (
plain) (
tree)
|
|
--
-- Dump Web Page GNAT Sockets Example
--
-- $Id$
--
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.Sockets; use GNAT.Sockets;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Streams;
use type Ada.Streams.Stream_Element_Count;
procedure dumpWebPage is
Client : Socket_Type;
Address : Sock_Addr_Type;
Channel : Stream_Access;
Send : String := (1 => ASCII.CR, 2 => ASCII.LF);
Offset : Ada.Streams.Stream_Element_Count;
Data : Ada.Streams.Stream_Element_Array (1 .. 256);
-- public IP of www.rtems.org as of 25 September 2007
-- Server : String := "216.186.189.3";
-- private OAR IP to test with
Server : String := "192.168.1.103";
begin
Initialize;
Create_Socket (Client);
Address.Addr := Inet_Addr(Server);
Address.Port := 80;
Connect_Socket (Client, Address);
Channel := Stream (Client);
Put_Line( "GET / HTTP/1.1" & Send );
Put_Line( "Host: " & Server & Send );
String'Write (Channel, "GET / HTTP/1.1" & Send);
String'Write (Channel, "Host: " & Server & Send & Send);
loop
Ada.Streams.Read (Channel.All, Data, Offset);
exit when Offset = 0;
for I in 1 .. Offset loop
Ada.Text_IO.Put (Character'Val (Data (I)));
end loop;
end loop;
end dumpWebPage;
|