I have the following code I am sending the result of intermediate predictions results from the client to server.
Client
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host_name = socket.gethostname()
host_ip = 'localhost'
print('HOST IP:', host_ip)
port = 9999
socket_address = (host_ip, port)
server_socket.bind(socket_address)
server_socket.listen(5)
while True:
client_socket, addr = server_socket.accept()
print('GOT CONNECTION FROM:', addr)
if client_socket:
vid = cv2.VideoCapture("D:/testing.mp4")
while (vid.isOpened()):
img, frame = vid.read()
image = img_to_array(frame)
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
image = preprocess_input(image)
preds = model.predict(image)
a = pickle.dumps(preds)
message = struct.pack("Q", len(a)) + a
client_socket.sendall(message)
client_socket.close()
server
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host_ip = 'localhost'
port = 9999
client_socket.connect((host_ip, port))
data = b""
payload_size = struct.calcsize("Q")
while True:
while len(data) < payload_size:
packet = client_socket.recv(4 * 1024)
if not packet: break
data += packet
packed_msg_size = data[:payload_size]
data = data[payload_size:]
msg_size = struct.unpack("Q", packed_msg_size)[0]
while len(data) < msg_size:
data += client_socket.recv(4 * 1024)
frame_data = data[:msg_size]
data = data[msg_size:]
frame = pickle.loads(frame_data)
While running the above code I am facing the below error
msg_size = struct.unpack("Q", packed_msg_size)[0] struct.error: unpack requires a buffer of 8 bytes
Thank you