Reputation: 53
I'm looking for a ZMQ-capable solution for a communication between an bound endpoint that is connected to 0 or 1 peers and no more than that. The communication is two-way, and the connection can be ended or severed at any point in time; and the connection can be re-establish with either a new peer or the same peer. It doesn't matter if the bound endpoint blocks or doesn't block if it doesn't have a peer on the other side.
What ZMQ socket pair would suit this use case the best? I was initially thinking REP/REQ, but the socket pair allows for multiple REQs to connect to one REP, which I don't want; it also will need to handle the "I'm waiting for a recv/I'm going to send something" lockstep paradigm when someone disconnects. PAIR also seems bad because it doesn't naturally handle the reconnect, but it has the "0 or 1 peer" restriction I want.
Any suggestions?
Upvotes: 5
Views: 2381
Reputation: 11558
The short answer: Unfortunately there isn't a pattern that exactly fits your needs out of the box.
The closest pattern is the ZMQ PAIR to PAIR pattern. However it has some limitations in the following ways:
ZMQ_PAIR sockets are designed for inter-thread communication across the zmq_inproc(7) transport and do not implement functionality such as auto-reconnection. ZMQ_PAIR sockets are considered experimental and may have other missing or broken aspects.
ROUTER and DEALER is the most flexible pattern. You can control it to set the restrictions you need.
Upvotes: 2