http://www.perlmonks.org?node_id=967651


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