I am trying to make a simple broker (i.e. star topology) that allows any DEALER
node to talk to any other DEALER
node that has also connected to the broker. Here is the current setup:
// Simple broker
#include <string>
#include <zmq.hpp>
#include <zhelpers.hpp>
using namespace std;
int main()
{
zmq::context_t context(1);
zmq::socket_t router(context, ZMQ_ROUTER);
router.bind("ipc://router.ipc");
while (true)
{
string from_address = s_recv(router);
string to_address = s_recv(router);
string message = s_recv(router);
s_sendmore(router, to_address);
s_sendmore(router, from_address);
s_send(router, message);
}
return 0;
}
This works, however, I feel like I just made this up and that it is inefficient to copy the incoming frames (esp. the data) into strings when I'm just swapping the positions of the first two frames and sending it right back out.
My question is - is there a standard way of doing what I am trying to do here?
It seems like every single google query sends me back to the monolithic Guide/Bible instead of implementation examples...