I use ZeroMQ to facilitate the publishing / subscribing environment I need. I am running the publishing server on machine A using Python (using EventLoop), and now I have one subscriber working in C ++ on computer B, and a second subscriber working in Python (using EventLoop) on computer C.
If machine B subscribes to machine A before machine C, then B receives signed messages, but C does not. Also, if I look at the established connections on machine A, there is only a connection for machine B, but not for C. If machine C subscribes to A before doing B, then it is the other way around.
Here is my publisher code:
import zmq from zmq.eventloop import ioloop, zmqstream ioloop.install() context = zmq.Context(1) socket = context.socket(zmq.PUB) publisher = zmqstream.ZMQStream(socket) socket.bind("tcp://*:1337") def publish(): publisher.send_multipart(("heartbeat", "OHAI")) ioloop.PeriodicCallback(publish, 5000).start() ioloop.IOLoop.instance().start()
Here is my Python subscriber code:
import zmq from zmq.eventloop import ioloop, zmqstream ioloop.install() context = zmq.Context(1) socket = context.socket(zmq.SUB) subscriber = zmqstream.ZMQStream(socket) socket.setsockopt(zmq.SUBSCRIBE, "heartbeat") socket.connect("tcp://pub.local:1337") def subscription(message): print "Message Received: %s" % (message[1]) subscriber.on_recv(subscription) ioloop.IOLoop.instance().start()
Why does my publisher not accept multiple incoming subscriber sockets? It is probably worth noting that several subscribers work fine when running on machine A, but I do not think that this is a problem with the firewall, because I tested the connections of subscribers from B and C to A with the firewall disabled.
zeromq
Bryan
source share