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,f69eb259f3ed2afb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!news.aset.psu.edu!not-for-mail From: "Bob Spooner" Newsgroups: comp.lang.ada Subject: Re: Using GNAT.Sockets Date: Thu, 14 Apr 2005 10:45:31 -0400 Organization: Penn State University, Center for Academic Computing Message-ID: References: <1113404846.310840.322920@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: nat4.arl.psu.edu X-Trace: f04n12.cac.psu.edu 1113489937 17760 128.118.40.79 (14 Apr 2005 14:45:37 GMT) X-Complaints-To: usenet@f04n12.cac.psu.edu NNTP-Posting-Date: Thu, 14 Apr 2005 14:45:37 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Xref: g2news1.google.com comp.lang.ada:10460 Date: 2005-04-14T10:45:31-04:00 List-Id: Hi Markwork66, wrote in message news:1113404846.310840.322920@z14g2000cwz.googlegroups.com... > We are just converting to GNAT and I am used to the traditional TCP > send/receive using an address and byte count to send/receive data. I've > used the Receive_Socket command in GNAT.Sockets and I am having trouble > receiving all the bytes. The "Last" parameter is not always equal to > the size of the message I'm sending and I don't see a way to call back > into the procedure to receive the rest of the bytes. > > Further, we have many different sized messages and, from my little > playing with GNAT sockets, it seemed the "Item" parameter is the only > way to specify the number of bytes you want to receive. So, does that > mean I would have to declare an array of bytes (the "Item" parameter) > for all of my messages and the then do an unchecked conversion or a > copy_bytes routine to get the data into my Ada message data type? > > Any help anybody could provide would be most appreciated. > I'm assuming that you are using TCP/IP, which is a stream-oriented protocol. The messages you are sending may be broken up into shorter lengths depending on the characteristics of the underlying mechanism used for moving the information. There are several solutions to your problem, among them: 1) If you are using the same compiler and type of computer, operating system, etc. at both ends of the circuit, you can use the default streams mechanism to send the messages by using the Input and Output attributes. Unlike C++, the default representation format for the streams facility for Ada is binary rather than ASCII. 2) You can layer a record protocol on top of TCP/IP where you prepend your message with a fixed-length integer field representing the number of bytes in the message. Then when you receive the message, you first read the number of bytes, and then issue additional reads until you have received the entire message. I hope this helps. Bob