import io import socket import struct import time import cv2 # Connect a client socket to my_server:8000 (change my_server to the # hostname of your server) client_socket = socket.socket() client_socket.connect(('my_server', 8000)) # Make a file-like object out of the connection connection = client_socket.makefile('wb') try: cap = cv2.VideoCapture("run.mp4") while True: ret, frame = cap.read() if frame == None: break image = cv2.imencode('.jpg', frame) stream = image.tobytes() # Write the length of the capture to the stream and flush to # ensure it actually gets sent connection.write(struct.pack(' 30: break # Reset the stream for the next capture stream.seek(0) stream.truncate() # Write a length of zero to the stream to signal we're done connection.write(struct.pack('