From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7db5fb0599fd4b76 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!feeder.xsnews.nl!feeder.news-service.com!skynet.be!skynet.be!newspost001!tjb!not-for-mail Date: Mon, 02 May 2005 14:11:15 +0200 From: Adrien Plisson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: fr-fr, fr-be, fr, en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: TCP/IP Sockets with GNAT.Sockets References: <1115001752.291144.218410@z14g2000cwz.googlegroups.com> In-Reply-To: <1115001752.291144.218410@z14g2000cwz.googlegroups.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <427618e9$0$7743$ba620e4c@news.skynet.be> Organization: -= Belgacom Usenet Service =- NNTP-Posting-Host: 5b3c2a71.news.skynet.be X-Trace: 1115035881 news.skynet.be 7743 81.246.231.57:4564 X-Complaints-To: usenet-abuse@skynet.be Xref: g2news1.google.com comp.lang.ada:10867 Date: 2005-05-02T14:11:15+02:00 List-Id: 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