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=0.1 required=5.0 tests=BAYES_00,PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.yTvCNOh9TRCAIcX40YItlQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada x Datagram Sockets Date: Fri, 8 Feb 2019 22:38:47 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <47f17695-f9a5-4024-b2da-3f13209dc4fd@googlegroups.com> <818f5ff4-f18d-42b8-950d-9b597c012aa4@googlegroups.com> <62406dfb-54c9-4db3-b461-0ad72d4a782c@googlegroups.com> <519fd5e0-eb4e-432e-85cc-d7a37510c957@googlegroups.com> <9c63d0be-fffa-4dab-a879-921fd723b8d8@googlegroups.com> NNTP-Posting-Host: yTvCNOh9TRCAIcX40YItlQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:55473 Date: 2019-02-08T22:38:47+01:00 List-Id: On 2019-02-08 21:35, Rego, P. wrote: >> What the OP needs to do is >> >> 1. Get Length, the length of the data. >> 2. Create C : Interfaces.C.char_array (1 .. Length) >> 3. Transfer the data into C >> 4. Use Interfaces.C.To_Ada (C) to transform C into an Ada String > > Simple enough, would you know how transfer the data into this C? I am trying in this path > > loop > -- Receive and print message from client Ping > Channel := SOCKETS.Stream (Socket, Address); > > Text_IO.Put_Line (Integer'Image (Channel'Size)); > > declare > Channel_Size : Integer := Integer (Channel'Size); > type Buffer_Type is new Interfaces.C.char_array (1 .. Interfaces.C.size_t (Channel_Size)); > type Stream_Buffer_Type is new String (1 .. Integer (Channel_Size)); > > function Copy_Arr is new Ada.Unchecked_Conversion (Buffer_Type, Stream_Buffer_Type); > > --Buffer : Buffer_Type; > Stream_Buffer : Stream_Buffer_Type; > > begin > --Buffer := String'Input (Channel); > > --!!!! Stream_Buffer := Stream_Buffer_Type (String'Input (Channel)); > end; > end loop; declare Packet : Stream_Element_Array (1..Max_Size); Last : Stream_Element_Offset; From : Sock_Addr_Type; loop Receive_Socket (Socket, Packet, Last, From); -- UDP from anyone declare Text : String (1..Natural (Last)); begin for Index in 1..Last loop Text (Integer (Index)) := Character'Val (Packet (Index)); end loop; Put_Line (Image (From) & ">|" & Text & "|"); end; end loop; For UDP there is no need to have packet length because packet=frame. For TCP, you read the header first which usually determine the length. Then you read the length stream elements. After that you start to decode. P.S. It is good practice to keep framing (packet I/O) separate from payload encoding/decoding. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de