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

Perl Socket server waiting for clients

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

代码简介

暂无

Perl代码片段

use IO::Socket;

$server = IO::Socket::INET->new
(
    LocalPort => 1247,
    Type      => SOCK_STREAM,
    Reuse     => 1,
    Listen    => 5 
) or die "Could not create server.\n";

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

    unless (defined($child_pid = fork())) {die "Can not fork.\n"};

    if ($child_pid) {

        while ($line = <$client>) {

            print "Read this from client: $line";

        }

    } else {

        while ($line = <>) {

            print $client $line; 

        }
    }    
}

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