Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-08-22 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (144 votes), past polls