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

核能气质少年 提交于 2020-01-01 20:02:02

问题


Does Publish-Subscribe method work if:

  1. publisher and subscribers are in different networks (I've checked once - it works)
  2. subscribers are behind NAT\firewall

In both cases packet routing works correctly.

As I understand PUB\SUB uses the same TCP transport, so if PUB\SUB doesn't work so standard windows winsock doesn't work too? Is PUB\SUB proxy (like that http://zguide.zeromq.org/page:all#toc34) needed if packet routing mechanism is undefined only?


回答1:


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()


来源:https://stackoverflow.com/questions/12171461/zeromq-usage-of-publish-subscribe-pattern-in-different-networks-behind-nat-fire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!