Mat Harris wrote:
> i have sorted the two-way communication stuff but no I am having
> trouble doing the multithreaded version. I have no experience using
> fork or anything to do with spawing or pid's.
> 
> Looking at the multithreaded server example on the sockets page on
> perldoc.com, please could someone help me convert the attached server
> script into a multithreaded server.

Mat, I don't know how to do multithreading, but it's very easy to make a
forking server.

Your server contains the following loop:

    while ($client = $server->accept) {
      
       ... code to handle client goes here ...

    }

Basically, you want everything in the block to execute in a separate
process, so the server can go back to the accept() call and wait for another
client to connect. To do this, you just need to add the following code (new
lines marked with asterisks):

*   $SIG{CHLD} = 'IGNORE';       # don't create zombies

    while ($client = $server->accept) {

*      defined(my $pid = fork) or die "Couldn't fork: $!";
*      next if $pid;             # parent loops back to accept()
     
       # now we're the child, executing in a separate process

       ... code to handle client goes here ...

       # when child is finished, it MUST call exit()
*      exit;
    }   


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to