“非插座上的插座操作”在发送ImagezMQ的一个图像之后

发布于 2025-01-23 17:01:29 字数 1297 浏览 2 评论 0原文

我试图通过使用Python Library ImagezMQ在某个端口上连续发送JPG图像(包含在文件夹中)的服务器,然后删除它们。 我不明白为什么正确发送一张图像后,服务器具有错误的“套筒上的套接字操作”。这是代码:

import imagezmq
import os
from time import sleep
import cv2
import subprocess

PORT = 6002
sender_max_res = imagezmq.ImageSender("tcp://*:{}".format(PORT), REQ_REP=False)
print("Creating ImageSender publishing on tcp://*:{}...".format(PORT))
images_dir = "./to_send"

while os.listdir(images_dir):
    try:
        # send image
        print("Files {}".format(os.listdir(images_dir)))
        filename = os.listdir(images_dir)[-1]
        filename_complete = images_dir + "/" + filename
        image = cv2.imread(filename_complete)
        _, image_buffer = cv2.imencode(".JPG", image)
        exif_data_str = "metadata here..."
        sender_max_res.send_jpg(exif_data_str, image_buffer)
        print("Sending file {}".format(filename_complete))
        sleep(5)

        # remove file
        command = "rm " + filename_complete
        print("Executing {}".format(command))
        subprocess.call(command, shell=True)
        sleep(1)

    except Exception as ex:
        print(ex)
    finally:
        sender_max_res.close()
        pass

我真的不明白为什么我有这个问题,可能是连接到AWS EC2(Ubuntu Server)的使用。但是我认为这不是端口或地址的问题,因为第一张图像已正确发送! PS还可以使用安全选项,端口6002是打开的。

I'm trying to implement a server continuously sending jpg images (contained in folder) on a certain port with the Python library imagezmq and then deleting them.
I don't understand why, after sending one image correctly, the server has the error "Socket operation on non-socket". Here's the code:

import imagezmq
import os
from time import sleep
import cv2
import subprocess

PORT = 6002
sender_max_res = imagezmq.ImageSender("tcp://*:{}".format(PORT), REQ_REP=False)
print("Creating ImageSender publishing on tcp://*:{}...".format(PORT))
images_dir = "./to_send"

while os.listdir(images_dir):
    try:
        # send image
        print("Files {}".format(os.listdir(images_dir)))
        filename = os.listdir(images_dir)[-1]
        filename_complete = images_dir + "/" + filename
        image = cv2.imread(filename_complete)
        _, image_buffer = cv2.imencode(".JPG", image)
        exif_data_str = "metadata here..."
        sender_max_res.send_jpg(exif_data_str, image_buffer)
        print("Sending file {}".format(filename_complete))
        sleep(5)

        # remove file
        command = "rm " + filename_complete
        print("Executing {}".format(command))
        subprocess.call(command, shell=True)
        sleep(1)

    except Exception as ex:
        print(ex)
    finally:
        sender_max_res.close()
        pass

I really don't get why I have this problem, probably is connected to the use of AWS EC2 (ubuntu server). But I don't think it's a problem of port or address, because the first image is sent correctly!
P.s. also the security options are fine, the port 6002 is open.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文