Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: New to perl: IO Select question :(

by Roger (Parson)
on Aug 21, 2005 at 00:16 UTC ( #485450=note: print w/replies, xml ) Need Help??


in reply to Re^2: New to perl: IO Select question :(
in thread New to perl: IO Select question :(

Try this instead, in case the select method returns a reference to an array:
my $rhSet = IO::Select->select($readSet, undef, undef, 0); foreach $rh(@$rhSet) {


You should also read the perldoc for IO::Select, there is a short example at the end.
perldoc IO::Select EXAMPLE Here is a short example which shows how "IO::Select" could be used to write a server which communicates with several sockets while also listening for more connections on a listen socket use IO::Select; use IO::Socket; $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080); $sel = new IO::Select( $lsn ); while(@ready = $sel->can_read) { foreach $fh (@ready) { if($fh == $lsn) { # Create a new socket $new = $lsn->accept; $sel->add($new); } else { # Process socket # Maybe we have finished with the socket $sel->remove($fh); $fh->close; } } }

Replies are listed 'Best First'.
Re^4: New to perl: IO Select question :(
by CompleteMoron (Initiate) on Aug 21, 2005 at 00:20 UTC
    Yup I'v seen that example, and tried it with can_read aswell, same thing happens :(
      my $sock = IO::Socket::INET->new( Proto=>"tcp", LocalHost=>"Localhost", Listen=>16, Reuse=>1, LocalPort=>$ARGV[0] ) or die("Could not create socket!\n") +; my $readSet = new IO::Select(); $readSet->add($sock); my $rhSet = IO::Select->select($readSet); while(my @ready = $rhSet->can_read(0)) { foreach $rh(@ready) { if($rh == $sock) { $newSocket=$rh->accept(); $readSet->add($newSocket); } else { $buf=<$rh>; if($buf) { printf "$buf"; } else { $readSet->remove($rh); close($rh); } } } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://485450]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-11-26 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?