tags:

views:

772

answers:

1

I'm making a program that retrieves decently large amounts of data through a python socket and then immediately disconnects when the information is finished sending. But I'm not sure how to do this

All the examples on the web are of tcp clients where they have

while 1:
   data = sock.recv(1024)

But this creates a look to infinite loop to receive data via the socket, does it not?

I need to figure out the size of the message coming in and loop through it in buffer-sized increments to get the full message. And after the message has finished sending, I would like to disconnect, although i think the connection will be closed from the other end. Any help would be nice

Thanks

+5  A: 

You've probably missed a very important part of those examples - the lines that follow the "recv()" call:

while 1:
    data = conn.recv(1024)
    if not data: break
    conn.send(data)
conn.close()
Milen A. Radev