I kept working on the code and changed a few lines.
Now I get no error, however, it looks like that the client is not fully executed,
in other words, I should be able to see these two statements being printed on the last lines
Here is my edited code for serve and client.
SERVER
In addition, only one picture is received, instead of all of them.
Now I get no error, however, it looks like that the client is not fully executed,
in other words, I should be able to see these two statements being printed on the last lines
print('Successfully get the file') print('connection closed')but I don't. What exactly is stopping it?
Here is my edited code for serve and client.
SERVER
import 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......") 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(1024) 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 from PIL import Image 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 True: print('receiving data...') data = s.recv(1024) print('data=%s', data) print('Successfully get the file') s.close() print('connection closed')By the way, this time I included my code into the code box as usual, but somehow it doesn't look like I did. I am not sure why.
In addition, only one picture is received, instead of all of them.