comp.lang.ada
 help / color / mirror / Atom feed
* Sockets Example
@ 2004-04-11 19:39 wave
  2004-04-12  4:01 ` tmoran
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: wave @ 2004-04-11 19:39 UTC (permalink / raw)


Hello there, I was wondering if anybody could provide some socket
examples for ada as I've looked everywhere and only found really
pretty basic things (ie the header of the gnat.sockets package)

Could anybody explain to me how you'd go about querying a http server
and getting a response? Even retrieve a specific file? The code I'm
trying to use below isnt working as I'd of expected it too, and I know
it's probably not even remotely close to how it should be!


with Gnat.Sockets;
use Gnat.Sockets;
with Ada.Text_Io;
use Ada.Text_Io;

procedure meh is 
   Socket  : Socket_Type;  
   Server  : Sock_Addr_Type;  
   Channel : Stream_Access;
begin

   Initialize;
   Create_Socket (Socket, Family_Inet, Socket_Datagram);

   Server := (
      Addr => Addresses (Get_Host_By_Name ("www.adahome.com"), 1),
      Port => 80,
      Family => Family_Inet
      );

   -- ? Bind_Socket (Socket, Server);

   Connect_Socket (Socket, Server);  
   Channel := Stream (Socket);

-- Some (hopefully correct) example of how to submit the correct data
to the webserver, with carrige returns and line feeds.

  String'Output (Channel,

       "GET /index.html HTTP/1.1" & Character'Val(13) &
Character'Val(10) &
       "Host: www.adahome.com" & Character'Val(13) & Character'Val(10)
&
       "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.7b) Gecko/20040407 Firefox/0.8.0+" & Character'Val(13) &
Character'Val(10) &
       "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
& Character'Val(13) & Character'Val(10) &
       "Accept-Language: en-us,en;q=0.5" & Character'Val(13) &
Character'Val(10) &
       "Accept-Encoding: gzip, deflate" & Character'Val(13) &
Character'Val(10) &
       "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" &
Character'Val(13) & Character'Val(10) &
       "Keep-Alive: 300" & Character'Val(13) & Character'Val(10) &
       "Cache-Control: max-age=0" & Character'Val(13) &
Character'Val(10) &
       "Connection: keep-alive" & Character'Val(13) &
Character'Val(10)

       );

   loop
      declare
  Message : String := String'Input (Channel);
      begin
  Server := Get_Address (Channel);
         Put_Line (Message & " from " & Image (Server));
      end;
   end loop;

   Close_Socket (Socket);

end meh;


Cheers for ANY insight into my problem you people can give.

Mut.



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-04-16 23:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-11 19:39 Sockets Example wave
2004-04-12  4:01 ` tmoran
2004-04-12 10:52   ` wave
2004-04-12 10:54   ` wave
2004-04-12 17:16 ` Marc A. Criley
2004-04-12 18:25   ` tmoran
2004-04-12 19:00     ` Jano
2004-04-13  7:54     ` Pascal Obry
2004-04-16 18:17     ` Craig Carey
2004-04-13 12:31 ` Gorazd Bozic
2004-04-16 23:38 ` wave

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox