comp.lang.ada
 help / color / mirror / Atom feed
From: "fabio de francesco" <fmdf@tiscali.it>
Subject: Re: TCP/IP Sockets with GNAT.Sockets
Date: 2 May 2005 07:55:40 -0700
Date: 2005-05-02T07:55:40-07:00	[thread overview]
Message-ID: <1115045740.838321.306480@g14g2000cwa.googlegroups.com> (raw)
In-Reply-To: <427618e9$0$7743$ba620e4c@news.skynet.be>

Adrien Plisson wrote:
> fabio de francesco wrote:
> > Hello,
>
> hello !
>
> > Today is the first time I try to use sockets in Ada programs, even
if I
> > have some practical knowledge of programming with TCP/IP sockets in
C.
> > Because I didn't find any better tutorial on working with
GNAT.Sockets
> > I am relying on comments in file g-socket.ads from GCC/GNAT sources
> > where there is not a complete and detailed coverage of the subject.
> >
> > (1) Do you know any better tutorial?
>
> personnally, no. the GNAT reference manual says:
> "The chapter here simply gives a brief summary of the facilities
> available. The full documentation is found in the spec file for the
> package. The full sources of these library packages, including both
> spec and body, are provided with all GNAT releases."
> so, you can rely on the comments in g-socket.ads (which contains some

> full examples).

>From my message: "...I am relying on comments in file g-socket.ads from
GCC/GNAT sources...". Sorry for my poor English, I know that sometimes
I'm unable to express clearly, but I had already done exactly what you
now suggest.

> also, the behavior is identical to other sockets
> implementation (C, Python, or others) so don't hesitate to read
> manuals for other languages.

I also said I already know how to program with sockets in C.

> the only big difference is in Streams, which is Ada specific...

This is the only problem I wrote I had. I didn't know how to use
Send_Socket() and Receive_Socket() because the specs say they take
"Stream_Element_Array" and "Stream_Element_Offset" as parameters.

If you read g-socket.ads you won't find any usage example either of the
above mentioned functions or related parameters.

> [...]
> > I hadn't too many problems with exchanging messages and everything
> > works. The problem is that I was only able to use Streams for
> > communicating between them and I can't understand at all how to use
> > Receive_Socket() and Send_Socket() because they use
> > "Stream_Element_Array" and "Stream_Element _Offset" in place of
> > Strings. I know that by using Streams they can't communicate with C
> > programs and I've read that Streams are everything but efficient.
>
> streams are not specially inefficient (to the contrary, my dear). the

> problem is that many people do not clearly understand them !

That was what I have found by searching and reading this NG through
Google for help in using them right before posting.

> so let's explain Ada streams:
>
> streams are defined as a tagged record in Ada.Streams, which is to be

> derived in order to implement stream specific behavior: how to send
or
> receive data from stream. Streams define 2 procedures for reading and

> writing data onto them. on this side of streams, data are represented

> as Stream_Element grouped in Stream_Element_Array. a single
> Stream_Element may represent a byte you send over the network for
> example.
>
> at this end of streams, there is no data type: what is important is
> the type of streams you manipulate.
>
> on the other end, you are concerned with data types you read from or
> write to stream, but not with the type of streams. on this end, every

> streams are equal, may it be file, socket, or anything else. this is
> achieved through stream oriented attributes: 'Read, 'Write, 'Input
and
> 'Output. those attributes allow you to read or write a specific data
> type from/to a stream. for example: Integer'Input( S ) will read an
> integer from the stream S (whatever stream type S is). the behavior
of
> those attribute may be overriden through an attribute definition
clause.
>
> at this end of streams, there is no stream type: what is important is

> the type of data you manipulate.
>
> in fact, stream attributes are kind of double-dispatching
> operations... at the light of this explaination, you should re-read
> ARM95 13.13, and may better understand them.

Thank you for this detailed explanation.

> so, now you understand this, you may ask yourself if you really need
> to use Receive_Socket() or Send_Socket(): they are intended to
> programmers writing their own stream attributes... (note that this
> could be useful to communicate with a C program through socket
streams).

This is exactly the problem that I have overcome with the help I've had
from Eric Jacoboni. Both my client and server programs didn't work at
exchanging messages with C programs. After searching the web I
discovered I had to use Receive_Socket() and Send_Socket() in order to
get over that problem.

S : String := "Hello";
SEA : Stream_Element_Array(1..S'Length);
for SEA'Address use S(S'First)'Address;
Last : Stream_Element_Offset;
Send_Socket( Socket, SEA, Last );

This is not exactly what someone can find in a Python or C manual. :-)

You're right about the fact that the fault is mine for not knowing
Streams while a Socket package isn't required to give any explanations
on the usage of a subject that is not so closely related.

Anyway the package authors cover about 350 lines with an procedure
example only using Streams, without ever saying why and when you should
sometimes choose Receive_Socket() and Send_Socket() in place of
Streams.

> i hope this explaination clarified things a bit and was useful to you

> (or others)... language lawyers will surely push it a little bit
further.
>
> --
> rien

Thanks, it helped a lot to make me to understand Streams. I hope this
time I have been able to make myself clear. 

fabio de francesco




  reply	other threads:[~2005-05-02 14:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-02  2:42 TCP/IP Sockets with GNAT.Sockets fabio de francesco
2005-05-02  5:58 ` Eric Jacoboni
2005-05-02 12:11 ` Adrien Plisson
2005-05-02 14:55   ` fabio de francesco [this message]
2005-05-02 16:10     ` Adrien Plisson
2005-05-02 17:56       ` Eric Jacoboni
2005-05-02 18:30         ` Poul-Erik Andreasen
2005-05-02 19:10           ` Simon Wright
2005-05-03 13:00             ` Poul-Erik Andreasen
2005-05-03 21:48               ` Simon Wright
2005-05-04  8:01               ` Character'First, ASCII.NUL and others (Was: Re: TCP/IP Sockets with GNAT.Sockets) Adrien Plisson
2005-05-04 13:40                 ` Poul-Erik Andreasen
2005-05-02 20:37           ` TCP/IP Sockets with GNAT.Sockets fabio de francesco
2005-05-02 20:52             ` Adrien Plisson
2005-05-03 12:04               ` fabio de francesco
2005-05-03 12:22                 ` Adrien Plisson
2005-05-03 13:17             ` Poul-Erik Andreasen
2005-05-02 20:44         ` Adrien Plisson
2005-05-02 22:10           ` Eric Jacoboni
2005-05-02 23:42             ` tmoran
2005-05-02 19:39     ` Björn
2005-05-02 20:22       ` fabio de francesco
2005-05-09  4:03         ` Dave Thompson
replies disabled

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