你的分享就是我们的动力 ---﹥

Perl 使用 fork 的 socket 服务器

时间:2013-05-30 00:09来源:www.chengxuyuans.com 点击:

代码简介

暂无

Perl代码片段

#!/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
    }
}

转载注明地址:http://www.chengxuyuans.com/Perl/63104.html