Skip to content Skip to sidebar Skip to footer

Send An Image Through Socket As Binary Data

I have a multithreaded echo server: from socket import * import threading import thread def handler(clientsock,addr): while 1: data = clientsock.recv(BUFSIZ) i

Solution 1:

If you have the image data in a string, you can just replace your call to clientsock.send(msg) with clientsock.sendall(image_data). You can just read the image data out of a file using something along the lines of:

image = open('my_image.jpg', 'rb')
image_data = image.read()
image.close()

Post a Comment for "Send An Image Through Socket As Binary Data"