From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Sockets Example Sought
Date: Fri, 23 Nov 2012 23:40:59 +0100
Date: 2012-11-23T23:40:59+01:00 [thread overview]
Message-ID: <17vopoh3g5mg4.jv11ioybge4k$.dlg@40tude.net> (raw)
In-Reply-To: 2012112315585358568-rblove@airmailnet
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 <rblove@airmail.net> 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<grin>.
>>>
>>> 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
next prev parent reply other threads:[~2012-11-28 5:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-23 17:17 Sockets Example Sought Robert Love
2012-11-23 18:32 ` Simon Wright
2012-11-23 21:58 ` Robert Love
2012-11-23 22:40 ` Dmitry A. Kazakov [this message]
2012-11-24 18:27 ` Robert Love
2012-11-24 21:01 ` Dmitry A. Kazakov
2012-11-27 3:37 ` Robert Love
2012-11-27 8:41 ` Dmitry A. Kazakov
2012-11-27 15:05 ` Mark Lorenzen
2012-11-23 23:08 ` Simon Wright
2012-11-28 4:43 ` anon
2012-11-30 5:04 ` Robert Love
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox