Streaming jetson usb camera to remote pc

Hi! I’m trying to stream jetson usb camera to my pc by setting up the remote pc as server and jetson as client. Both are connected to the same wifi but i doesn’t show the image on the remote pc.

Client’s code:

import cv2, socket, pickle, os  
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 10000000)
serverip="my ip "
serverport=6666

cap = cv2.VideoCapture(0)
while True:    
    ret,photo = cap.read()    
    
    cv2.imshow('streaming', photo)    
    
    ret, buffer = cv2.imencode(".jpg", photo,[int(cv2.IMWRITE_JPEG_QUALITY),30])    
    x_as_bytes = pickle.dumps(buffer)    
    
    s.sendto(x_as_bytes,(serverip , serverport))    
    
    if cv2.waitKey(10) == 13:        
        
          break  
cv2.destroyAllWindows()
cap.release()

and the server’s code:

import cv2, socket, numpy, pickle
s=socket.socket(socket.AF_INET , socket.SOCK_DGRAM)
ip=''
port=6666
s.bind((ip,port))

while True:
    x=s.recvfrom(1000000)
    clientip = x[1][0]
    data=x[0]
    print(data)
    data=pickle.loads(data)
    print(type(data))
    data = cv2.imdecode(data, cv2.IMREAD_COLOR)
    cv2.imshow('server', data) #to open image
    if cv2.waitKey(10) == 13:
        break
cv2.destroyAllWindows()

Code is not mine but i would like to know why is not working. Help pls!

please be aware, that you cannot send/read more than 64k bytes in a single udp packet. (so your SOL_SOCKEToption there is already bs, fooling you into believing something wrong)
unlike tcp, it also wont auto-fragment your data into several packets, or care for the correct order of those.
then, it would probably need a ‘blocking’ socket on the receiving side, else most of the time there’s nothing to read from (and you dont even check !), a proper ‘0.0.0.0’ server address (not ‘’), etc.

low-level networking is hard !
dont expect silly copy-pasting stuff you dont understand to work, ever !

again, throw it away, it’s all bs !

maybe you can just install gstreamer on your jetson, and use that to serve a video stream ? and use VideoCapture to receive it on the other side ?
(w/o breaking your neck at writing own low-level code for this)

well, fragmentation happens on the IP layer.

TCP doesn’t “fragment”, it’s a stream where the granularity is a single byte. UDP can’t fragment, it’s unrelated datagrams of upto 64K size.

Python is okay with binding to the empty string, which is equivalent to all interfaces.

you can use nonblocking sockets but why bother? just use any method for polling (select, poll, epoll, whatever). the cv.waitKey sets the pace because it contains implicit delays.

that is insufficient.

you need to debug your code. learn to use python’s debugger, or at least use printlining (“printf-debugging”) to follow the flow of execution and observe the state.

your code looks like it should work in principle. perhaps your network/OS firewall just drops the packets or the packets are caught by a NAT or whatever.

above all that: your problem doesn’t involve OpenCV except for the attempt to decode some data and show it in a GUI. it doesn’t even involve gstreamer (thread was tagged as “gstreamer”). it’s just python and sockets. please bring your issue to a forum that deals with general programming education.