Here is some code that I wrote that works with non-blocking and multiple clients.while (1) { print "yo\n"; while ( my @handles = $self->{daemon}->can_read(1) ) { foreach ( @handles ) { if ($_ == $self->{listener}) { my $new_sock = $self->{listener}->accept or die "accept: $!"; $self->{daemon}->add( $new_sock); } else { my @rawmsg = $_->getlines; if ($rowmsg[0]){ # Or what ever the index of the message is print @rawmsg; } else { $self->{daemon}->remove($_); $_->close; } } } }
use IO::Socket; use IO::Select; my $sock = new IO::Socket::INET (LocalHost => '127.0.0.1', LocalPort => 1200, Listen => 5, Proto => 'tcp', Reuse => 1, ) or die $!; my $handles = new IO::Select(); $handles->add($sock); while (1){ print "yo"; my ($s_handles) = IO::Select->select($handles, undef, undef, 1); for my $hndl (@$s_handles){ if ($hndl == $sock){ $handles->add($hndl->accept()); } else { if (my $line = <$hndl>){ print $line; } else { $handles->remove($hndl); close ($hndl); } } } }
In reply to Re: non-blocking select with IO::Select
by c-era
in thread non-blocking select with IO::Select
by dash2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |