Forking Servers : Server « Network « Perl






Forking Servers

    

#!/usr/bin/perl
use warnings;
use IO::Socket;
my $servsock = IO::Socket::INET->new( Listen => 5,LocalPort => 5000);
sub reap { 
   wait(); 
   $SIG{CHLD} = \&reap;
} # catch and handle children dying
$SIG{CHLD} = \&reap;
while($client = $servsock->accept()) {
    if ($pid = fork()) {
        close $servsock; 
    } else {
        close $client; #let the child deal with the client socket
    }
}

   
    
    
    
  








Related examples in the same category

1.Two way server
2.Time server
3.The server and the client are on the same machine
4.Simple server
5.Socket answer
6.Socket pair
7.Socket server waiting for clients
8.Read from server
9.Send data from client to server