我试图从一个程序发送一个视频流到任意数量的客户端(比如0-10个客户端)。
我可以很容易地用一个发布者和一个订阅者来完成这个任务,但是如果我启动另一个客户端应用程序,在我关闭第一个应用程序之前,它不会接收到任何数据。
我的代码如下所示:
服务器
import zmq
import imageio
import simplejpeg
context = zmq.Context()
publisher = context.socket(zmq.PUB)
publisher.connect("ipc:///tmp/v4l")
gif = imageio.get_reader('video.mp4')
while True:
for frame in gif:
frame = simplejpeg.encode_jpeg(frame)
publisher.send(frame)客户端
import zmq
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.bind("ipc:///tmp/v4l")
subscriber.setsockopt(zmq.SUBSCRIBE, b'')
i = 0
while True:
data = subscriber.recv()
print(i)
i = i+1在文档(https://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/pubsub.html)中,它声明
场景2是更常见的通用模式,多个订阅者订阅由发行者发布的消息/主题。虽然我不知道为什么这对我不起作用.
发布于 2021-06-28 12:49:31
使发布服务器绑定()和多个订阅者连接()。您只能绑定/侦听同一端点一次,但可以多次连接。
https://stackoverflow.com/questions/68163525
复制相似问题