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

Perl 双路客户端

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

Perl 双路客户端代码

use IO::Socket;

$socket = IO::Socket::INET->new
(
    PeerAddr => 'server.com',
    PeerPort => 1247,
    Proto    => "tcp",
    Type     => SOCK_STREAM
) or die "Could not create client.\n";

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

if ($child_pid) {
    while ($line = <>) {
        print $socket $line;
    }
} else {
    while($line = <$socket>) {
        print "Read this from server: $line";
    }
}

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