Nov-06-2019, 09:35 PM
The server is supposed to send all pictures from a folder to the client.
By changing the number inside of the parenthesis of s.recv() in the client side
I was able to display two pictures.
My question is, what is stopping my code from sending/displaying them all?
How to fix it?
P.S.
the number inside the parenthesis is the size of one of the pictures.
SERVER
By changing the number inside of the parenthesis of s.recv() in the client side
I was able to display two pictures.
My question is, what is stopping my code from sending/displaying them all?
How to fix it?
P.S.
the number inside the parenthesis is the size of one of the pictures.
SERVER
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, "*.jpg") print(st) return glob.glob(st) list1 = readFileImages() print(list1, "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 (readFileImages()): f = open(pics, 'rb') l = f.read() #while (l): c.sendall(l) #print('Sent ', repr(l)) print(len(l), 'LENGTH L') print(f, "how many files") f.close() print('Done sending') c.send('Thank you for connecting'.encode())CLIENT
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)) s.send('Hello server!'.encode()) with open('received_file.jpg', 'wb') as f: print('file is open') while f: print('receiving data...') #data = s.recv(439813) data = s.recv(440179) print('data=%s', data, "ASDFASDSADFASDFVSSDSAFSADDFDSAFD") f.write(data) print('Successfully get the files') print('connection closed') print(type(data)) print(len(data)) image = Image.open(io.BytesIO(data)) image.show() s.close()