How to receive a data file of unknown length using a python socket?

John Machin sjmachin at
Sun Jul 19 02:12:32 CEST 2009

On Jul 19, 7:43 am, Irmen de Jong <irmen.NOS... at> wrote:
> twgray wrote:
> > I am attempting to send a jpeg image file created on an embedded
> > device over a wifi socket to a Python client running on a Linux pc
> > (Ubuntu).  All works well, except I don't know, on the pc client side,
> > what the file size is?  
> You don't. Sockets are just endless streams of bytes. You will have to design some form
> of 'wire protocol' that includes the length of the message that is to be read.

Apologies in advance for my ignorance -- the last time I dipped my toe
in that kind of water, protocols like zmodem and Kermit were all the
rage -- but I would have thought there would have been an off-the-
shelf library for peer-to-peer file transfer over a socket
interface ... not so?

More information about the Python-list mailing list