Bug report
Bug description:
I am trying to build a video chat using sockets (basically send a video from the client side and receive a video on the server side).
I ran up this problem that no one on the internet encountered before:
Already tried specifying each protocol on the dump call, but it did not change anything. All the answers online are error caused by version mismatch (python 2.7 calling protocol=3, as an example).
Here are my files:
Server.py:
import cv2
import socket
import pickle
import numpy as np
import struct
host = ''
port = 8000
def main():
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((host, port))
print("Socket bind complete")
server.listen(10)
print("Listening...")
conn, addr = server.accept()
data = b''
payload_size = struct.calcsize("s")
while True:
while len(data) < payload_size:
data += conn.recv(4096)
msg = data
msg_size = len(msg)
if msg_size == 0:
break
while data < msg:
data += conn.recv(4096)
frame = data
data = b''
frame = pickle.loads(frame)
cv2.imshow('VideoS', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
conn.close()
if __name__ == "__main__":
main()
client.py
import cv2
import socket
import pickle
import struct
server = 'localhost'
port = 8000
def main():
# camera
cap = cv2.VideoCapture(-1)
if cap.isOpened() == False:
print("Couldn't open the Camera. Exiting..")
exit()
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect((server, port))
print("Connected to " + server + " at " + str(port))
while cap.isOpened():
ret, frame = cap.read()
if ret == False:
print("Couldn't read from camera")
break
# display
cv2.imshow("VideoC", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# frame serialised
data = pickle.dumps(frame,protocol=pickle.HIGHEST_PROTOCOL)
clientsocket.sendall(struct.pack('s', data)+data)
clientsocket.sendall(struct.pack('s', b''))
print("Exiting..")
cap.release()
cv2.destroyAllWindows()
clientsocket.close()
if __name__ == "__main__":
main()
CPython versions tested on:
3.9
Operating systems tested on:
Linux