comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Need help creating a multi client TCP server with Ada
Date: Fri, 7 Feb 2014 18:53:09 +0100
Date: 2014-02-07T18:53:09+01:00	[thread overview]
Message-ID: <q305pbm2bgkm.veiygnht3x15.dlg@40tude.net> (raw)
In-Reply-To: cfc49abb-92cc-48b6-b8c6-9f81d734b4c0@googlegroups.com

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

  reply	other threads:[~2014-02-07 17:53 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 [this message]
2014-02-07 18:34 ` Simon Wright
replies disabled

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