[Tutor] Reading text lines from a socket

Lloyd Kvam pythontutor at venix.com
Sat Feb 28 18:34:33 EST 2004


Sockets deal with packetized data.  The network protocols do not guarantee
keeping the data in line oriented chunks - even if the data starts out that way.

You need to deal with extracting lines from chunks.  So long as the connection is
working properly, this is easy.  The challenge occurs when the remainder of a line
never gets delivered.  The best strategy depends upon the details of what you are
doing.

Sandip Bhattacharya wrote:

> The socket objects only allow data to be read in by chunks (recv()). How 
> do I manage to read in data one line at a time where a line is defined 
> as a lf/cr-lf terminated test string?
> 
> In other words how can one write their own clients for reading/writing 
> data for text based protocols like smtp?
> 
> Thanks,
> 
>   Sandip
> 

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-653-8139
fax:	801-459-9582




More information about the Tutor mailing list