python - 试图发送一个大文件,python 套接字

标签 python sockets opencv

我正在尝试创建从网络摄像头到其他服务器的实时流。我的问题是 我得到的框架对于套接字来说太大了
我收到这个错误:

error: [Errno 10040] A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself

这是我的代码:

 import numpy as np
import cv2
import socket
import sys
import select
cap = cv2.VideoCapture(0)
address = ('localhost', 6005)
client_socket=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    print (frame)
    client_socket.connect(('120.0.0.1', 6005))
    client_socket.sendto(frame, address)

我知道 c,我想也许我可以创建一个指向框架的指针并逐个发送它 所以我的问题是如何将此方法转换为 python,如果可能的话

最佳答案

来自 Ans :

Your image is too big to be sent in one UDP packet. You need to split the image data into several packets that are sent individually.

If you don't have a special reason to use UDP you could also use TCP by specifying socket.SOCK_STREAM instead of socket.SOCK_DGRAM. There you don't have to worry about packet sizes and ordering.

你也可以看看Ans

关于python - 试图发送一个大文件,python 套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21016689/

相关文章:

python - 在 Numba 中,如何调用在 GPU 上运行的递归函数?

python - 如何更改 Django 错误报告电子邮件的主题?

python - 比较两个深度学习框架的特征响应

java - 如何在 Spring Integration 中从 TCP 读取流(消息)

python - 在 Docker 中使用 OpenCV (Python) 访问网络摄像头?

OpenCV 怪胎 : Fast Retina KeyPoint descriptor

python - 将代码中的输出图像保存到系统中而无需在 python 中截屏

c - OpenBSD 内核模块调用网络函数

java - 在导出远程对象时,如何强制 RMIIO 库使用我的自定义 RMI 套接字工厂?

python - 使用 Python OpenCV,您将如何提取特定颜色边界框内的图像区域?