Python Forum
send all pictures instead of just two
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
send all pictures instead of just two
#3
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:
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
Reply


Messages In This Thread
send all pictures instead of just two - by mcgrim - Nov-06-2019, 09:35 PM
RE: send all pictures instead of just two - by mcgrim - Nov-07-2019, 09:49 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020