in reply to Multi threaded server [fork]

Semantic quibble: these aren't threads, they're processes. There's a big difference with regard to synchronicity and shared resources.

That said, what happens if you close the connection in the parent after you've forked off a child? If one process still has a connection open to the client, how does the client know it's finished reading? You might be able to get away with this:

while (my $client = $server->accept()) { # as normal }

This is untested, though, and I haven't looked in a networking book to be sure.

Replies are listed 'Best First'.
Re: Re: Multi threaded server [fork]
by Deda (Novice) on Aug 07, 2003 at 08:22 UTC
    Unfortunatly i just got some higer priority work, so i'll have to stick to 'one client at a time' server for some time. To answer your questions: close conn. in parent: This would probbably work fine, since everything i do in the parent works as expected (have no time to test, though). how do server and client communicate: when server accepts the connection it forks off a child server, which, in a while loop, recieves one line of command and sends back the output. Last line of output is 'END\012\015', which indicates to the client stop reading. The client may then send a new command or 'SessionQuit\012\015', in which case the server closes the client connection and function returns.