I am trying to send a live video frame from my client (Raspberry Pi) to a server hosted on a laptop. Both of these devices are connected to the same network.
Server.py
import socket import sys import cv2 import pickle import numpy as np import struct HOST = '192.168.1.3' PORT = 8083 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) print 'Socket created' s.bind((HOST, PORT)) print 'Socket bind complete' s.listen(10) print 'Socket now listening' conn, addr = s.accept() 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.size
Client.py
import cv2 import numpy as np import socket import sys import pickle import struct cap = cv2.VideoCapture(0) clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) clientsocket.connect(('192.168.1.3', 8081)) while True: ret,frame = cap.read() data = pickle.dumps(frame) clientsocket.sendall(struct.pack("L", len(data)) + data)
My server on the laptop is not receiving any data . But when I run this client and the server on the same devices (for example, the server and the client on the laptop), it works fine.
I can send data from raspberries to a laptop (tested on the echo application).
Can anyone help me with this?
source share