Home » Python » python – Sending a lot of pictures over TCP-Exceptionshub

python – Sending a lot of pictures over TCP-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I’m trying to send a lot of pictures one by one over TCP. For some reason, on the receiving side I’m getting all of the information in the first pictures and the rest is blank (but exists).

Here is the receiving code, which loops through the number of the images:

def get_video(conn, index):
file_name = str(index) + '.png'
f = open(file_name, 'wb')
while True:
    print('receiving data...')
    data = conn.recv(1024)
    if not data:
        break
    f.write(data)
print('got one!')
f.close()

And here is the sender code. I’m calling this function for every photo I have:

def send_screenshot(nh_sock, img_path):
    f = open(img_path, "rb")
    data = f.read()
    nh_sock.send(data)
    f.close()
How to&Answers: