Reputation: 2541
I have the following task:
Clients connect to a server on 1 port (e.g. 8080). The server should remember them and after completing calculation it should send results to the clients. After that server gets some results again and again sends it to all clients. And so on.
How can server mantain connections with all clients?
Upvotes: 0
Views: 825
Reputation: 2541
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()
Upvotes: 0
Reputation: 6232
Do you actually need to maintain all connections from clients? I think, that "publish/subscribe" messaging model will satisfy described conditions. The server should "publish" results and clients should "subscribe" on this updates. Simplest example for such "server" you can find in zguide code samples: wuserver.cpp
Upvotes: 1