comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Need help creating a multi client TCP server with Ada
Date: Fri, 07 Feb 2014 18:34:51 +0000
Date: 2014-02-07T18:34:51+00:00	[thread overview]
Message-ID: <lyppmy22lw.fsf@pushface.org> (raw)
In-Reply-To: 1408dd3b-f555-4b75-94ef-cdb9c06ed0ca@googlegroups.com

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().


      parent reply	other threads:[~2014-02-07 18:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-06 21:42 Need help creating a multi client TCP server with Ada alex.aanis
2014-02-06 22:23 ` adambeneschan
2014-02-06 23:40   ` alex.aanis
2014-02-07  8:48     ` Jacob Sparre Andersen
2014-02-07 17:16       ` alex.aanis
2014-02-07 17:53         ` Dmitry A. Kazakov
2014-02-07 18:34 ` Simon Wright [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox