comp.lang.ada
 help / color / mirror / Atom feed
From: clubley@remove_me.eisner.decus.org-Earth.UFP (Simon Clubley)
Subject: Re: GNAT.Sockets Problems
Date: 12 May 2003 06:38:48 -0500
Date: 2003-05-12T06:38:48-05:00	[thread overview]
Message-ID: <FlbBRwa5VIk2@eisner.encompasserve.org> (raw)
In-Reply-To: 28d8936a.0305091146.18a4dd57@posting.google.com

In article <28d8936a.0305091146.18a4dd57@posting.google.com>, file13@qlippoth.zzn.com (file13) writes:
> Howdy all, I've been tinkering with GNAT.Sockets on Mandrake 9.1 using
> the Gnat-3.15p linux binary and I'm simply trying to write the first
> day time client from Stevens UNIX Network Programming book with it and
> I can't seem to figure out what I'm doing wrong.
> 
> so far in Ada I have:
> 
> with Ada.Exceptions; use Ada.Exceptions;
> with Ada.Text_IO; use Ada.Text_IO;
> with GNAT.Sockets; use GNAT.Sockets;
> 
> procedure Daytime_Client is
>    Target  : Inet_Addr_Type := Inet_Addr ("127.0.0.1");
>    Socket  : Socket_Type;
>    Server  : Sock_Addr_Type;
>    Channel : Stream_Access;
> begin
>    Initialize;
>    Create_Socket (Socket);
>    Server := (Family_Inet, Target, 13);
> 
>    Connect_Socket (Socket, Server);
> 
>    Channel := Stream (Socket, Server);
>    Put_Line (String'Input (Channel));
               ^^^^^^

That's your problem. 'Input is trying to read the dope information for the
String datatype; so this will never work.

> 
>    Shutdown_Socket (Socket);
>    Close_Socket (Socket);
>    Finalize;
> 
> exception when E : others =>
>    Put_Line (Exception_Name (E)
>              & ": " & Exception_Message (E));
> end Daytime_Client;
> 
> It appears to connect just fine because if I turn off the server it
> gives me:
> 
> $ ./daytime_client
> GNAT.SOCKETS.SOCKET_ERROR: [111] Connection refused
> 
> but if it's on I'm getting the following error:
> 
> $ ./daytime_client
> ADA.IO_EXCEPTIONS.END_ERROR: s-stratt.adb:188
> 
> Also if I change the port to something else open like 22 I get a
> segmentation fault:
> 
> $ ./daytime_client
> Segmentation fault
> 
> Why wouldn't it get a similar error if it's only ripping the banner
> off of the server port?
> 
> Am I doing something wrong with the streams (this is the first time
> I've used Ada's streams) or do I need to GNAT.Sockets.Receive_Socket? 

As it happens, I have also been looking at GNAT.Sockets for the first time
this weekend (and, as a result, Ada.Streams for the first time as well.)

I also tried String'Input before realising why that would not work, and
also got a segmentation fault, presumably because the GNAT runtime is trusting
the information that's it's reading as the dope information, which I found
disappointing as that's the kind of thing that I would expect from C and
not Ada.

> If so can anyone provide me with an example?  I know in C you have to
> use a loop, but I didn't know if that was necessary with Ada.Streams. 
> I tried it with Receive_Socket also, but I could not figure out how to
> print the output to regular stdout....
> 

You could always do a (maybe unchecked) conversion and then treat the
Stream_Elements as a stream of characters. I ended up doing that in order
to get it working with Receive_Socket.

And now for a request of my own:

I have been looking at GNAT.Sockets as part of some investigations into
deciding if my next project will be written in Ada or C. I am finding
GNAT.Sockets to be cumbersome when it comes to reading data, and I am
wondering how others use it.

In case it makes a difference, I am using GNAT.Sockets with GtkAda and am
passing the socket file descriptor to GtkAda so that a callback can be
called when data is available to read, so I must not block in the callback.

Thanks for any information,

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP       
VMS advocate: One who makes a Mac advocate look like a beginner at advocacy.



      parent reply	other threads:[~2003-05-12 11:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-09 19:46 GNAT.Sockets Problems file13
2003-05-11  0:51 ` Craig Carey
2003-05-12 11:38 ` Simon Clubley [this message]
replies disabled

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