问题
Does Publish-Subscribe method work if:
- publisher and subscribers are in different networks (I've checked once - it works)
- 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