I continued to work on it, by turning bytes back into images, and I am now getting an error on the client side,
even though the files seem to be transferred.
The directory in the client contains a few images, and I desire to send them all to the client.
even though the files seem to be transferred.
Error:Traceback (most recent call last):
File "C:/Users/PycharmProjects/client-server/client.py", line 31, in <module>
img = Image.open(io.BytesIO(data))
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 0x076EE450>
SERVERimport cv2 import time import socket import glob import os host = "127.0.0.1" port = 5000 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((host, port)) s.listen(5) print("server started...") path1 = (r"C:\Users\Desktop\opencvpics") def readFileImages(): st = os.path.join(path1, "*.png") print(st) return glob.glob(st) list1 = readFileImages() print(list1, "list1......") print(type(list1)) while True: c, addr = s.accept() print(f"connection from {addr} has been established !") c.send(bytes("welcome to the server".encode())) for pics in list1: f = open(pics, 'rb') l = f.read(1024000) while (l): c.send(l) print('Sent ', repr(l)) l = f.read(1024) f.close() print('Done sending') c.send('Thank you for connecting'.encode())CLIENT
import socket import cv2 from PIL import Image import io import pickle host = "127.0.0.1" port = 5000 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.send('Hello server!'.encode()) with open('received_file.png', 'wb') as f: print('file is open') #while f: print('receiving data...') data = s.recv(1024) print('data=%s', data, "ASDFASDSADFASDFVSSDSAFSADDFDSAFD") f.write(data) print('Successfully get the files') print('connection closed') print(type(data)) print(len(data)) img = Image.open(io.BytesIO(data)) img.show() s.close()P.S.
The directory in the client contains a few images, and I desire to send them all to the client.