2
use strict; use warnings;
use IO::Socket;
use IO::Select;
my $read_select = IO::Select->new();
my $write_select = IO::Select->new();
my $socket = IO::Socket::INET->new(
LocalHost => '127.0.0.1',
LocalPort => '5556',
Proto => 'tcp',
Listen => 50,
Reuse => 1,
) or die "Could not create socket: $!";
print "Socket Created . Waiting for connection ...\n";
## poll to accept new connection or to receive data from a connection
$read_select->add($socket);
print "Added socket to read list ";
my $reade;
my $newconn;
my @read;
my @write;
while(1) {
@read = $read_select->can_read();
foreach my $reade(@read) {
if($reade == $socket) {
print "New conn received";
my $newconn = $reade->accept();
$write_select->add($newconn);
}
else {
print "data received";
}
}
}
@write = $write_select->can_write();
foreach my $write(@write) {
$write->send("got ur data");
}
我想使用select語句來輪詢連接。爲什麼如果我使用無限循環,沒有連接被接受。它工作正常,沒有時(1)使用select來輪詢連接 - TCP服務器
很好。發現! – 2013-04-04 11:07:32