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!news.mb-net.net!open-news-network.org!.POSTED.2804:431:81bf:5e00:3cb7:e830:40d1:65e8!not-for-mail From: Daniel Norte de Moraes Newsgroups: comp.lang.ada Subject: Re: Broadcast / iterate to all Connection objects via Simple Components? Date: Mon, 13 Feb 2023 20:33:54 -0000 (UTC) Organization: MB-NET.NET for Open-News-Network e.V. Message-ID: References: <392dd5d3-4df1-403f-b703-ee6f750dbc81n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 13 Feb 2023 20:33:54 -0000 (UTC) Injection-Info: gwaiyur.mb-net.net; posting-host="2804:431:81bf:5e00:3cb7:e830:40d1:65e8"; logging-data="1655734"; mail-complaints-to="abuse@open-news-network.org" User-Agent: Pan/0.149 (Bellevue; 4c157ba) Cancel-Lock: sha1:Zz8aHJmYfINw2aJojK2PJvsbn7Q= X-User-ID: U2FsdGVkX188XEYOw4JvgBzSKUXoAOE51j7eD3gkSoO3ClJ/zgB3pKwI9cjGITxE Xref: reader01.eternal-september.org comp.lang.ada:64920 List-Id: Em Tue, 7 Feb 2023 12:29:39 -0800 (PST), A.J. escreveu: > Hello everyone, Hi! Wellcome! > > In an effort to better learn network programming in Ada, I've been > working through the Protohacker Challenges (https://protohackers.com/), > and the current challenge (number 3) is to create a chat server. > > I am using a TCP Connections Server with Simple Components, specifically > a Connection_State_Machine, but I've run into a problem.  I'm trying to > send a message received via "procedure Process_Packet (Client : in out > Server_Connection)" to all connected Clients. > > My (potentially incorrect) thought on how to accomplish this is to > iterate through all of the clients currently connected, and use Send to > send the message received to those clients.  I've been struggling with > how to actually do this though, since I couldn't use "function > Get_Clients_Count (Listener : Connections_Server) return Natural" from > within Process_Packets. > > Another thought I had could be to just place every message received in a > central queue, and then once all of the packets have been received, to > then process that queue and send the results to every connected client. > > I tried overriding "procedure On_Worker_Start (Listener : in out > Connections_Server)", thinking that I could use it to read such a queue, > but it never seemed to be called from within my program and I'm still > unsure how to iterate through the Connection objects anyway. > > Am I approaching this the right way, or am I missing something very > obvious?  I've read the test files that came with Simple Components, > including the data server but couldn't see a way to get each client to > interact with each other. If I didn't explain this well enough, please > let me know, I'll be happy to clarify. > > Kind regards, > AJ. Do you is obliged to use gnat-sockets ? Adare_Net has support to syncronous IO multiplex; With Adare_Net you can create virtually infinite groups of network pools to get and send data on demand. and you can discover if peers closed connections and others things too. you can use syncronous i/o multiplexing groups of network pools in dedicate ada tasks (or similar) to get truly real-time network programming and apps. Thanks! https://github.com/danieagle/adare-net https://github.com/danieagle/adare-net/blob/main/adare_net/src/adare_net- sockets-polls.ads Each poll_type has a limit of 255 entries (more than that can be very slower) But you can have as many poll_types as you want. Thanks! Best Whishes, GrateFull, Dani.