python端为客户端client
import zmq
import numpy as np
import cv2
import os
import time
# 图像文件夹路径
folder_path = "./"
context = zmq.Context()
socket = context.socket(zmq.PUSH)
socket.connect("tcp://localhost:5557")
print("start send....")
# 读取文件夹中的所有图片
for filename in os.listdir(folder_path):
# 判断文件是否为图片
if filename.endswith(".jpg") or filename.endswith(".png") or filename.endswith(".jpeg"):
# 读取图像文件
image = cv2.imread(os.path.join(folder_path, filename))
data = cv2.imencode(".jpg", image)[1].tobytes()
# 发送请求消息
print("send....", os.path.join(folder_path, filename))
socket.send(data)
#time.sleep(1)
# 发送一个空消息表示图片发送结束
socket.send_string("", flags=0)
print("image send finish, end")
time.sleep(1)
socket.close()