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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,e8c6974546bc3f7f X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.217.69 with SMTP id ow5mr3742242pbc.0.1354079954784; Tue, 27 Nov 2012 21:19:14 -0800 (PST) Path: s9ni15231pbb.0!nntp.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!novia!news-hub.siol.net!news.mi.ras.ru!goblin-spool!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Sockets Example Sought Date: Fri, 23 Nov 2012 23:40:59 +0100 Organization: cbb software GmbH Message-ID: <17vopoh3g5mg4.jv11ioybge4k$.dlg@40tude.net> References: <2012112311175432190-rblove@airmailnet> <2012112315585358568-rblove@airmailnet> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: kWJV5lTRAyCzy8lsfOrlcw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Received-Bytes: 3234 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-11-23T23:40:59+01:00 List-Id: On Fri, 23 Nov 2012 15:58:53 -0600, Robert Love wrote: > On 2012-11-23 18:32:52 +0000, Simon Wright said: > >> Robert Love writes: >> >>> Does anyone have an example of a multi-client server in Ada they care >>> to share? It should use the Gnat.Sockets package. I've seen samples >>> but they don't seem complete, or at least my understanding isn't >>> complete. >>> >>> Thanks in advance. >> >> task body Server in http://goo.gl/bXVw7 ? (lines 59 .. 143) > > What happens at line 120, the else clause on if Server = Socket_Server? > Is that where data is read in on the socket? Socket-select might be a bit difficult to start with. Unless you expect hundreds of simultaneous connections, there is a much simpler pattern that uses 1-2 tasks (half- or full-duplex I/O) per connection with so-called blocking sockets: Client : Sock_Addr_Type; Server : Sock_Addr_Type; Socket : Socket_Type; Data : Socket_Type; begin Server.Addr := ...; Server.Port := ...; Create_Socket (Socket); Bind_Socket (Socket, Server); Listen_Socket (Socket); loop Accept_Socket (Socket, Data, Client); -- Start an I/O task, give it Data to communicate over. -- Client holds the address of the client. The task will -- dispose the socket Data calling Shutdown_Socket and -- then Close_Socket on it, when communication is over end loop; > I assume the client opens the socket and the server detects it, then at > various times the client makes data requests by sending string data. That happens later on when the client connects its socket. A client does: Create_Socket Bind_Socket -- Client address Connect_Socket -- Server address -- I/O Shutdown_Socket Close_Socket The server listening to a socket gets a new socket when its calls to Accept_Socket. Accept waits for a client to come. This happens per each connection, i.e. for each client connection there is one accept completed on the server side. After accept returned a socket, this socket and the client's socket are connected, so that when one side writes something into its socket another side reads that from the socket of its own. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de