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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Need help creating a multi client TCP server with Ada Date: Fri, 07 Feb 2014 18:34:51 +0000 Organization: A noiseless patient Spider Message-ID: References: <1408dd3b-f555-4b75-94ef-cdb9c06ed0ca@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="f3a204fd0da52c1307d65ca023946f38"; logging-data="1594"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18m9u1m1PRWyxk85QfTVVsqvsdZ1E3kE1I=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) Cancel-Lock: sha1:JkSVzAKE9JMLMLmaowm2D4c3DJ0= sha1:hGC9LmvnF5sxxpAlx2nozfvM9EU= X-Original-Bytes: 3117 Xref: number.nntp.dca.giganews.com comp.lang.ada:184712 Date: 2014-02-07T18:34:51+00:00 List-Id: alex.aanis@gmail.com writes: > Code is on github: goo.gl/RvNIei It'd be a Good Idea not to include the contents of your bin/ and obj/ directories in your checked-in items! They're useless to anyone who clones the repo (unless they're running the same OS and compiler as you, of course, but that's unlikely). gnatmake's -p switch is your friend (create any needed directories if necessary). Actually I see you have obj/doc/, shouldn't that be just doc/? Looking at TCP.Server.Client_Type (in V2), you have task body Client_Type is Stream : Sockets.Stream_Access; begin loop accept Set_Stream (S : in Sockets.Stream_Access) do Stream := S; end Set_Stream; accept Write (Message : in String) do String'Output ( Stream, Message ); end Write; accept Read (Message : out String) do Message := String'Input ( Stream ); end Read; end loop; end Client_Type; which won't do what you want; every pass through the loop the task waits for a call on Set_Stream, then on Write ... you need something more like task body Client_Type is Stream : Sockets.Stream_Access; begin -- Must have a stream before anything else accept Set_Stream (S : in Sockets.Stream_Access) do Stream := S; end Set_Stream; loop select accept Write (Message : in String) do String'Output ( Stream, Message ); end Write; or accept Read (Message : out String) do Message := String'Input ( Stream ); end Read; end select; end loop; end Client_Type; > 2. How can I know if one client has been disconnected? If you try to write to it and get a Socket_Error; or if you try to read from it and get a successful completion with zero bytes read (or, of course, a Socket_Error; but I think that'll only happen if you've closed the server end). Q. How do you know whether to try to read from the socket? A. Use GNAT.Sockets.Selector_Type and Check_Selector().