8

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

asked Nov 14, 2008 at 2:04

1 Answer 1

21

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()
answered Nov 14, 2008 at 2:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.