“非插座上的插座操作”在发送ImagezMQ的一个图像之后
我试图通过使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论