in reply to Re: IO::Select and sockets
in thread IO::Select and sockets

OK, that code doesn't block.

Trying...

Hey, I managed to make it work! :-D

I had tried the can_read before, but only now did it work (probably I was doing something differently than what you suggested).

Thanks, runrig.

Since I had a lot of trouble finding this information, I'll put here the script I have working at the moment so that others may solve this problem faster in the future:

#!/usr/bin/perl -w use strict; use IO::Socket; use IO::Select; my $sock=new IO::Socket::INET (Localhost => '127.0.0.1', LocalPort => '4000', Proto => 'tcp', Listen => 5, ReuseAddr => 1, ); die "Socket could not be created. Reason $!" unless $sock; my $select = IO::Select->new(); $select->add($sock); while (my @sockets = $select->can_read()) { for my $incoming (@sockets) { if ($incoming == $sock) { my $new_sock = $incoming->accept; $select->add($new_sock); } else { print "new guy calling: $incoming\n"; } } } close($sock);