ZeroMQ Usage of publish-Subscribe pattern in different networks, behind NAT/firewalls

家住魔仙堡 提交于 2019-12-04 21:32:55

I've found some code uses PUB\SUB model and works with NAT here http://grokbase.com/t/zeromq/zeromq-dev/112q9934vg/nat-firewall-pub-sub-traversal:

Publisher that connects, rather than binds:

import zmq
ctxt = zmq.Context()
pub = ctxt.socket(zmq.PUB)
pub.connect("tcp://127.0.0.1:2000")
while 1:
pub.send(os.urandom(5))

Subscriber that binds, rather than connects:

import zmq
ctxt = zmq.Context()
sub = ctxt.socket(zmq.SUB)
sub.bind("tcp://127.0.0.1:2000")
while 1:
sub.rcv()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!