Problems with read_eager and Telnet

Jack Diederich jackdied at gmail.com
Mon Feb 28 18:09:17 CET 2011


On Mon, Feb 28, 2011 at 11:50 AM, Robi <roberto.inzerillo at gmail.com> wrote:
>> Telnet sends two kinds of data over the same channel (a simple TCP
>> stream).  It sends the bytes you actually see in your terminal and it
>> sends control commands that do things like turn echo on/off and
>> negotiate what terminal type to use.  Each time telnetlib reads from
>> the socket it puts the control stuff in one bucket and stores the
>> plain text in a buffer to return from all the read_* commands.
>>
>> read_eager() returns the plain text that has already been read from
>> the socket.  That might be a partial line.  It won't try to read from
>> the socket to get a full line.  That's why it is fast, because it
>> never does I/O.
>
> Ok, that's a start (I'm reading RFC 854 in the meanwhile). Still that
> doesn't help me much (sorry, I know it's me, not you).
>
> You mean read_eager() doesn't wait until it gets a complete reading of
> a line, instead it reads what's on the socket (even if it's to quick
> and there's till nothing) and let's the python script running anyway,
> right?
> Then with the subsequent read_eager() it will read (if there's
> something more on the socket in the meanwhile) the previous data bits
> and maybe the new ones too (a new line of data) into a single data
> chunk. Is that why I get sometimes repeated empty lines followed by
> many consequent lines all together out of a single read_eager() call?

Yes. read_eager() will never actually read from the socket, if it has
any data it has already read & processed it will return those.  If you
call it enough times it will just start returning empty strings
because it never asks the socket to read & wait for new data.

-Jack



More information about the Python-list mailing list