summaryrefslogtreecommitdiffstats
path: root/dumpwebpage/dumpwebpage.adb
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-09-27 14:43:02 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-09-27 14:43:02 +0000
commit09ee756ce5a4553e280bfe542c5859ec8e36cc55 (patch)
treef91a62db1e9fc5c075af7b7ba479a40c3a644833 /dumpwebpage/dumpwebpage.adb
parent2007-09-27 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadada-examples-09ee756ce5a4553e280bfe542c5859ec8e36cc55.tar.bz2
2007-09-27 Joel Sherrill <joel.sherrill@oarcorp.com>
* ChangeLog, Makefile, README, dumpwebpage.adb: New files.
Diffstat (limited to 'dumpwebpage/dumpwebpage.adb')
-rw-r--r--dumpwebpage/dumpwebpage.adb52
1 files changed, 52 insertions, 0 deletions
diff --git a/dumpwebpage/dumpwebpage.adb b/dumpwebpage/dumpwebpage.adb
new file mode 100644
index 0000000..c7cc82b
--- /dev/null
+++ b/dumpwebpage/dumpwebpage.adb
@@ -0,0 +1,52 @@
+--
+-- 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;