From: Adrien Plisson <aplisson-news@stochastique.net>
Subject: Re: TCP/IP Sockets with GNAT.Sockets
Date: Mon, 02 May 2005 14:11:15 +0200
Date: 2005-05-02T14:11:15+02:00 [thread overview]
Message-ID: <427618e9$0$7743$ba620e4c@news.skynet.be> (raw)
In-Reply-To: <1115001752.291144.218410@z14g2000cwz.googlegroups.com>
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). also, the behavior is identical to other sockets
implementation (C, Python, or others) so don't hesitate to read
manuals for other languages.
the only big difference is in Streams, which is Ada specific...
[...]
> 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 !
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.
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).
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
next prev parent reply other threads:[~2005-05-02 12:11 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 [this message]
2005-05-02 14:55 ` fabio de francesco
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