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 ステートメントを使用して接続をポーリングしようとしています。無限ループを使用すると、接続が受け入れられないのはなぜですか。while(1) がなくても問題なく動作します