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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Need help creating a multi client TCP server with Ada Date: Fri, 7 Feb 2014 18:53:09 +0100 Organization: cbb software GmbH Message-ID: References: <1408dd3b-f555-4b75-94ef-cdb9c06ed0ca@googlegroups.com> <173b40e2-b288-4375-9842-e6058e565379@googlegroups.com> <87vbwrmhpg.fsf@adaheads.sparre-andersen.dk> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dRN93LcgZmpMwxQ2TpSF2g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:18430 Date: 2014-02-07T18:53:09+01:00 List-Id: On Fri, 7 Feb 2014 09:16:03 -0800 (PST), alex.aanis@gmail.com wrote: > I've read about protected. But didn't quite understand it. How may I use > protected types within a task? You certainly do not need protected objects for a server implementation. Provided you are working using blocking sockets, once Accept_Socket returns a new socket = accepts a new connections, you start a task and pass the socket to it. The task then handles the connection. It also does the socket shutdown and closes the socket when the session is completed. Note that blocking sockets work up to a certain number of connections because the maximal number of tasks (threads) is usually limited in the OS. The maximal number of sockets is normally much higher. So if you have >100 clients would require a different design based on socket select. A full-duplex blocking socket I/O requires 2 tasks per socket. P.S. Regarding socket disconnect. You detect that when reading from the socket returns 0 octets. When sending you get an error. Typically on either read or write error or when you read 0 octets, you do socket shutdown, close the socket and dispose the reader and writer tasks, assuming a full-duplex communication, or the single I/O task if it is half-duplex. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de