http://qs321.pair.com?node_id=485452


in reply to New to perl: IO Select question :(

You never had the opportunity to accept any connection from the client side. Add $sock to IO::Select is no good, as it is not an "active channel" yet. Add the accept(), plus fix some minor syntax stuff, your code works.

use strict; use warnings; use IO::Socket; use IO::Select; my $sock = IO::Socket::INET->new( Proto=>"tcp", LocalHost=>"localhost", Listen=>16, Reuse=>1, LocalPort=>3000 ) or die("Could not create socket!\n") +; my $connection = $sock->accept(); my $readSet = new IO::Select(); $readSet->add($connection); while(1) { my @rhSet = IO::Select->select($readSet, undef, undef, 0); foreach my $rh (@{$rhSet[0]}) { my $buf=<$rh>; if($buf) { printf "$buf"; } else { $readSet->remove($rh); close($rh); } } }

Client side test code:

use IO::Socket; my $sock = IO::Socket::INET->new( Proto=>"tcp", PeerHost=>"localhost", PeerPort=>3000 ) or die("Could not create socket!\n") +; print $sock "abcd\n";

Well, I leave it to you to add back the code to accept further connections.