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

* Re: Sockets Example
  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
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: tmoran @ 2004-04-12  4:01 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
  Did you search at www.adaic.com or www.adapower.com or www.adaworld.com?
There's quite a bit of stuff, both simple and complex.
From a message I posted here 12/29/2003:
>FTP, HTTP, and SMTP packages, with example programs, are now available
>at www.adaworld.com, thanks to Stephane Richard.  Click on Ada Projects,
>then Ada Internet Projects, then Internet Protocols.  A .zip file has
>the specs.  Another zip file has bodies implemented with NC, a high
>level winsock binding based on, but Not requiring, Claw.  The third
>zip file has NC, with a short example program that fetches a webcam
>picture of current Silicon Valley weather.



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

* Re: Sockets Example
  2004-04-12  4:01 ` tmoran
@ 2004-04-12 10:52   ` wave
  2004-04-12 10:54   ` wave
  1 sibling, 0 replies; 11+ messages in thread
From: wave @ 2004-04-12 10:52 UTC (permalink / raw)


I just spent some time trying to navigate those sites, the search
function seems knackered on adaworld, and adapowers result isn't much
better. I'm having a look at the adasockets package now rather than
the gnat, it's just trying to find decent example of code. I'm on a
windows machine if it matters, if it's not any trouble could you point
me in the right direction?

Cheers for your responce


tmoran@acm.org wrote in message news:<rwoec.122904$JO3.82321@attbi_s04>...
>   Did you search at www.adaic.com or www.adapower.com or www.adaworld.com?
> There's quite a bit of stuff, both simple and complex.



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

* Re: Sockets Example
  2004-04-12  4:01 ` tmoran
  2004-04-12 10:52   ` wave
@ 2004-04-12 10:54   ` wave
  1 sibling, 0 replies; 11+ messages in thread
From: wave @ 2004-04-12 10:54 UTC (permalink / raw)


tmoran@acm.org wrote in message news:<rwoec.122904$JO3.82321@attbi_s04>...
> >FTP, HTTP, and SMTP packages, with example programs, are now available
> >at www.adaworld.com, thanks to Stephane Richard.  Click on Ada Projects,
> >then Ada Internet Projects, then Internet Protocols.  A .zip file has
> >the specs.  Another zip file has bodies implemented with NC, a high
> >level winsock binding based on, but Not requiring, Claw.  The third
> >zip file has NC, with a short example program that fetches a webcam
> >picture of current Silicon Valley weather.

Grrr, apologies I completely ignored that bit of your post for some
reason :) I'll check that out now, thanks.



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

* Re: Sockets Example
  2004-04-11 19:39 Sockets Example wave
  2004-04-12  4:01 ` tmoran
@ 2004-04-12 17:16 ` Marc A. Criley
  2004-04-12 18:25   ` tmoran
  2004-04-13 12:31 ` Gorazd Bozic
  2004-04-16 23:38 ` wave
  3 siblings, 1 reply; 11+ messages in thread
From: Marc A. Criley @ 2004-04-12 17:16 UTC (permalink / raw)


> Could anybody explain to me how you'd go about querying a http server
> and getting a response? Even retrieve a specific file?

If you want this functionality handed to you on a silver platter (with
source code of course), see the Ada Web Server (aws) at
http://libre.act-europe.fr/aws/main.html.

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

Thanks, I needed a cheer!  :-)

Marc A. Criley
McKae Technologies
m c @ m c k a e . c o m





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

* Re: Sockets Example
  2004-04-12 17:16 ` Marc A. Criley
@ 2004-04-12 18:25   ` tmoran
  2004-04-12 19:00     ` Jano
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: tmoran @ 2004-04-12 18:25 UTC (permalink / raw)


>> Could anybody explain to me how you'd go about querying a http server
>> and getting a response? Even retrieve a specific file?
>
>If you want this functionality handed to you on a silver platter (with
>source code of course), see the Ada Web Server (aws) at
>http://libre.act-europe.fr/aws/main.html.
  I understood the OP to want an HTTP client, not an HTTP server.  AWS is
indeed a server with all the goodies.  If he just wants to see the basics,
or to make a specialized, simple, custom server, Smplsrvr is one of the
demo programs with the $0, source included, intro version of Claw
(downloadable from www.rrsoftware.com).



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

* Re: Sockets Example
  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
  2 siblings, 0 replies; 11+ messages in thread
From: Jano @ 2004-04-12 19:00 UTC (permalink / raw)


tmoran@acm.org dice...
> >> Could anybody explain to me how you'd go about querying a http server
> >> and getting a response? Even retrieve a specific file?
> >
> >If you want this functionality handed to you on a silver platter (with
> >source code of course), see the Ada Web Server (aws) at
> >http://libre.act-europe.fr/aws/main.html.
>   I understood the OP to want an HTTP client, not an HTTP server.  AWS is
> indeed a server with all the goodies.  If he just wants to see the basics,
> or to make a specialized, simple, custom server, Smplsrvr is one of the
> demo programs with the $0, source included, intro version of Claw
> (downloadable from www.rrsoftware.com).

AWS has a client package, really simple to use.



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

* Re: Sockets Example
  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
  2 siblings, 0 replies; 11+ messages in thread
From: Pascal Obry @ 2004-04-13  7:54 UTC (permalink / raw)



tmoran@acm.org writes:

> >> Could anybody explain to me how you'd go about querying a http server
> >> and getting a response? Even retrieve a specific file?
> >
> >If you want this functionality handed to you on a silver platter (with
> >source code of course), see the Ada Web Server (aws) at
> >http://libre.act-europe.fr/aws/main.html.
>   I understood the OP to want an HTTP client, not an HTTP server.  AWS is
> indeed a server with all the goodies.  

AWS provides also a full Client API.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



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

* Re: Sockets Example
  2004-04-11 19:39 Sockets Example wave
  2004-04-12  4:01 ` tmoran
  2004-04-12 17:16 ` Marc A. Criley
@ 2004-04-13 12:31 ` Gorazd Bozic
  2004-04-16 23:38 ` wave
  3 siblings, 0 replies; 11+ messages in thread
From: Gorazd Bozic @ 2004-04-13 12:31 UTC (permalink / raw)


In article <4d01ad29.0404111139.58cd3e55@posting.google.com>,
wave <mutilation@bonbon.net> wrote:
> 
> 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!
...
>    Create_Socket (Socket, Family_Inet, Socket_Datagram);

HTTP is used over TCP and not UDP. Try Socket_Stream instead of 
Socket_Datagram.

Gorazd

-- 
Gorazd Bozic <gbx@email.si>



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

* Re: Sockets Example
  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
  2 siblings, 0 replies; 11+ messages in thread
From: Craig Carey @ 2004-04-16 18:17 UTC (permalink / raw)


On Mon, 12 Apr 2004 18:25:11 GMT, tmoran@acm.org wrote:

>>> Could anybody explain to me how you'd go about querying a http server
>>> and getting a response? Even retrieve a specific file?
>>

I have some simple Ada 95 code to parse HTTP/1.0 headers, here:

  http://www.ijs.co.nz/code/ada95_ptunnel_proxy_1.95b_win2k_unix.zip

It was not nicely packaged up. [Missing parts of the entire proxy easily
could be available].

In there is a small bind-socket subroutine that binds twice: firstly
exclusively, and when that fails, then in a sharing mode [i.e. then
ineffectively up until when the other program lets go of that local
socket].


>>[AWS:] http://libre.act-europe.fr/aws/main.html
>[Simplsrvr:] www.rrsoftware.com




--  Craig Carey   http://www.ijs.co.nz/ada_95.htm





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

* Re: Sockets Example
  2004-04-11 19:39 Sockets Example wave
                   ` (2 preceding siblings ...)
  2004-04-13 12:31 ` Gorazd Bozic
@ 2004-04-16 23:38 ` wave
  3 siblings, 0 replies; 11+ messages in thread
From: wave @ 2004-04-16 23:38 UTC (permalink / raw)


I appreciate your responses guys, thanks for the links and example files!



^ 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