Retrieving data through a python socket

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

All examples on the Internet relate to tcp clients, where they have

while 1:
   data = sock.recv(1024)

But this creates a look at the infinite loop for receiving data through the socket, right?

I need to find out the size of the incoming message and scroll through the steps of the buffer size to get the full message. And after the message has finished sending, I would like to disconnect, although I think that the connection will be closed from the other end. Any help would be nice

thanks

+5
source share
1 answer

, - , recv():

while 1:
    data = conn.recv(1024)
    if not data: break
    conn.send(data)
conn.close()
+17

All Articles