From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!reader01.eternal-september.org!aioe.org!W4+pUJJ+LMQSnRdpBvjvmw.user.46.165.242.91.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Sockets, Streams, and Element_Arrays: Much confusion Date: Sat, 31 Dec 2022 14:11:11 +0100 Organization: Aioe.org NNTP Server Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: gioia.aioe.org; logging-data="58699"; posting-host="W4+pUJJ+LMQSnRdpBvjvmw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org"; User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:64748 List-Id: 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 option) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de