When I had two threads, I used PAIR socket type. But now I am using two processes that can be either on one machine or on different machines. I don't need requests and responses, I don't need sending to multiple nodes, etc. I need same thing that I had with PAIR (async, bidirectional), but with processes and with network. What socket types should I use?
Best How To :
Unfortunately, your world has gotten a bit more complicated. There's no direct analog to the
PAIR/PAIR socket pairing in more widely distributed systems.
That said, if you keep roughly the same shape of the topology (two nodes connecting exclusively to each other and no other nodes) then you can pretty much achieve what you want using
ROUTER/DEALER or even
DEALER/DEALER (as you suggested in comments). Those sockets are sort of like
REQ/REP, but they don't enforce a strict request/response communication pattern, they are entirely unrestricted, so in effect you get the same thing. The only problem comes if you intend to add more nodes, at which point you have to start managing things a little differently, in particular the
DEALER socket doesn't allow you to choose which node you send to, it's strictly round robin.
But, doing that should get you what you're looking for (async, bidirectional).
ROUTER socket type can require a little additional complexity since you need to keep track of the "identifier" of the other node to be able to send back to it (you can get this almost for free, especially in your case with just one peer, by using it directly out of the sent message). Because this is an exclusive pair, you can ignore the round-robin uncertainty introduced by the
DEALER socket, and just go straight to
DEALER/DEALER, which gives you an unrestricted message pattern and doesn't require any management of identities.