From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Ada x <whatever> Datagram Sockets
Date: Fri, 8 Feb 2019 22:38:47 +0100
Date: 2019-02-08T22:38:47+01:00 [thread overview]
Message-ID: <q3kst5$16iq$1@gioia.aioe.org> (raw)
In-Reply-To: 9c63d0be-fffa-4dab-a879-921fd723b8d8@googlegroups.com
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
next prev parent reply other threads:[~2019-02-08 21:38 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-06 23:10 Ada x <whatever> Datagram Sockets Rego, P.
2019-02-07 0:42 ` Jere
2019-02-07 5:28 ` Rego, P.
2019-02-07 6:00 ` Egil H H
2019-02-07 6:41 ` Rego, P.
2019-02-07 7:23 ` Egil H H
2019-02-07 11:48 ` Jere
2019-02-08 19:41 ` Rego, P.
2019-02-08 20:31 ` Dmitry A. Kazakov
2019-02-08 21:56 ` Rego, P.
2019-02-07 8:28 ` Dmitry A. Kazakov
2019-02-07 10:08 ` Simon Wright
2019-02-08 0:15 ` Randy Brukardt
2019-02-08 8:25 ` Simon Wright
2019-02-08 13:24 ` Dmitry A. Kazakov
2019-02-09 1:01 ` Randy Brukardt
2019-02-10 17:54 ` Simon Wright
2019-02-11 8:39 ` Dmitry A. Kazakov
2019-02-11 13:35 ` Simon Wright
2019-02-11 14:25 ` Dmitry A. Kazakov
2019-02-11 15:19 ` Simon Wright
2019-02-11 16:04 ` Dmitry A. Kazakov
2019-02-11 23:19 ` Randy Brukardt
2019-02-12 11:35 ` Simon Wright
2019-02-08 19:44 ` Rego, P.
2019-02-07 11:47 ` Jere
2019-02-07 18:00 ` Jeffrey R. Carter
2019-02-08 20:35 ` Rego, P.
2019-02-08 21:26 ` Jeffrey R. Carter
2019-02-08 22:02 ` Rego, P.
2019-02-08 21:38 ` Dmitry A. Kazakov [this message]
2019-02-08 20:00 ` Rego, P.
2019-02-07 10:11 ` Simon Wright
2019-02-08 20:03 ` Rego, P.
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox