It looks like the bytes are transferred, thank you, but now I am not sure how to implement the image show algorithm.
I tried to change the client this way:
I tried to change the client this way:
import socket from PIL import Image import io host = "127.0.0.1" port = 5000 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) with open('received_file.jpg', 'wb') as f: print('file is open') chunk = s.recv(4096) f.write(chunk) received = 0 while True: # chunk = s.recv(4096) if not chunk: break received += len(chunk) f.write(chunk) image = Image.open(io.BytesIO(chunk)) image.show() print('Finished receiving. In total, {} bytes were received'.format(received)) s.close()but I get this error
Error: Traceback (most recent call last):
File "C:/Users/PycharmProjects/client-server/client_3.py", line 23, in <module>
image = Image.open(io.BytesIO(chunk))
File "C:\Users\PycharmProjects\client-server\venv\lib\site-packages\PIL\Image.py", line 2818, in open
raise IOError("cannot identify image file %r" % (filename if filename else fp))
OSError: cannot identify image file <_io.BytesIO object at 0x02F81FC0>
Process finished with exit code 1