Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^3: IO::Socket::INET->getline() function

by zentara (Archbishop)
on Apr 27, 2012 at 14:37 UTC ( #967651=note: print w/ replies, xml ) Need Help??

in reply to Re^2: IO::Socket::INET->getline() function
in thread IO::Socket::INET->getline() function

Yes, as confusing as you made it sound, you are on the right track. It seems obvious once you understand the problem of what waiting for a newline does, but just think about it. How does the receive end know when a line is finished? A line can be longer than 80 characters.... it could be a million characters, (or even more) all on the same line. So the receive end has to wait until it sees a newline, so it knows the line ended. Sockets are bi-directional, but do allow for just 1 way transfer. If you get into the recv and send methods, you will see you need to have a protocol, like the "over and back to you" in radio communication. So you can block the socket with recv too, because you tell it to wait until it receives x amount. Google for perl non blocking sockets and you will see the various ways you can get around this problem. Sysread the socket is usually the best way, and use IO::Select. There are plenty of examples on google already.

It only takes a little bit of logic to sysread the socket for lines. Probably an input storage buffer.

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Comment on Re^3: IO::Socket::INET->getline() function

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2015-11-27 20:27 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (731 votes), past polls