Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Answer: What is the easy way to check if the socket has data to read, before do a read()

by perlknight (Pilgrim)
on Jul 24, 2002 at 14:21 UTC ( #184851=categorized answer: print w/replies, xml ) Need Help??

Q&A > network programming > What is the easy way to check if the socket has data to read, before do a read() - Answer contributed by perlknight

Use IO::Select, pass the socket handle to it and use can_read method to detemine if the handle is ready, here's snippet from perldoc:
use IO::Socket; use IO::Select; $lsn = new IO::Socket::INET(Listen => 1, LocalPort => 8080); $sel = new IO::Select( $lsn ); while(@ready = $sel->can_read) { ... }

  • Comment on Answer: What is the easy way to check if the socket has data to read, before do a read()
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[choroba]: dereference ne creation
[choroba]: at least in my lingo
[moritz]: .oO( oh temps, oh moritz )
[GotToBTru]: you are correct, choroba, but of course there is no point in doing one without the other
[GotToBTru]: un less you're working on write-only memory
[1nickt]: my $x = $aohoaoh->[0]->{' foo'}->[0]->{'bar' }; should work
[thepkd]: not indexing
[thepkd]: getting data out of the ds
[choroba]: it depends. Give more details, please
[thepkd]: i used a series of {}'s but it dont work

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2016-12-06 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (104 votes). Check out past polls.