help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <>
Subject: Re: Sockets, Streams, and Element_Arrays: Much confusion
Date: Sat, 31 Dec 2022 14:11:11 +0100	[thread overview]
Message-ID: <topcdf$1pab$> (raw)
In-Reply-To: top8uc$cqv$

On 2022-12-31 13:11, Mark Gardner wrote:

> GNAT.Sockets gives me a Stream_Element_Array, which I can't find any 
> documentation on how to make use of other than "You should also be able 
> to get a Stream, which you should use instead" (About ten years ago, on 
> this very newsgroup, somebody said not to use streams with UDP, or at 
> least not GNAT.Sockets.Stream).

Stream_Element_Array is declared in Ada.Streams as

    type Stream_Element_Array is
       array(Stream_Element_Offset range <>) of
          aliased Stream_Element;

For communication purpose it is an array of octets. Your datagram is 
represented as a Stream_Element_Array or a slice of.

As for streams, yes, it does not make sense to use them for networking, 
unless you override all stream primitives. The reasons for that are

- non-portability of predefined primitives
- low efficiency for complex data types
- encoding inefficiency as well

You will need to handle some application protocol artifacts, checksums, 
counters, strange encodings, sequence number etc. It is easier to this 
directly on the Stream_Element_Array elements.

And, well, do not use UDP, expect for broadcasting. There is no reason 
to use it. For multicast consider delivery-safe protocols like PGM. For 
single cast use TCP/IP. (If you need low latency see the socket NO_DELAY 

Dmitry A. Kazakov

  reply	other threads:[~2022-12-31 13:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-31 12:11 Sockets, Streams, and Element_Arrays: Much confusion Mark Gardner
2022-12-31 13:11 ` Dmitry A. Kazakov [this message]
2022-12-31 13:50   ` Mark Gardner
2022-12-31 14:16     ` Dmitry A. Kazakov
2022-12-31 15:18     ` Jeffrey R.Carter
     [not found]   ` <>
2022-12-31 22:49     ` Jeffrey R.Carter
2022-12-31 22:55     ` Dmitry A. Kazakov
2022-12-31 17:39 ` Simon Wright
2022-12-31 19:36   ` Mark Gardner
2022-12-31 20:16     ` Dmitry A. Kazakov
2022-12-31 23:41       ` Simon Wright
2023-01-01  9:48         ` Dmitry A. Kazakov
2023-01-01 16:11           ` Simon Wright
2023-01-01 16:17         ` Niklas Holsti
2023-01-05  7:55 ` Daniel Norte de Moraes
2023-01-05 10:35   ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox