import socket
import struct
import cv2
import pickle

conn = socket.socket()
conn.connect(('localhost', 50007))

data = ""
payload_size = struct.calcsize("L")
while True:
    while len(data) < payload_size:
        data += conn.recv(4096)
    packed_msg_size = data[:payload_size]
    data = data[payload_size:]
    msg_size = struct.unpack("L", packed_msg_size)[0]
    while len(data) < msg_size:
        data += conn.recv(4096)
    frame_data = data[:msg_size]
    data = data[msg_size:]
    ###

    frame=pickle.loads(frame_data)
    print(frame)
    cv2.imshow('frame',frame)

conn.close()
