I worked a lot at the socket level, and if this is what you need, then yes Boost :: Asio is fine, if a little confusing.
However, if you just need to deliver data between processes (on the same or different machines), I would go a little further down the glass and look at something like ØMQ ; see how easy it is to get a “message” from another process:
zmq::context_t ctx(1); zmq::socket_t sock(ctx, ZMQ_REQ); sock.connect("tcp://localhost:5555"); zmq::message_t msg; while(sock.recv(&msg)) { std::string s(static_cast<char*>(msg.data()), msg.size()); std::cout << s; }
Sending is just as easy.
zmq::context_t ctx(1); zmq::socket_t sock(ctx, ZMQ_REP); sock.bind("tcp://*:5555"); std::string s = "Hello you!"; zmq::message_t msg(s.size()); memcpy(msg.data(), s.data(), s.size()); while(true) { sock.send(msg); sleep(1); }
ZeroMQ is very lightweight and takes care of connecting, reconnecting, transferring, framing, etc. All you need is your “message” payload, which you want to display on the other side of the pipe (in this case, we just used simple lines).
He also takes care of several more advanced messaging methods, such as pub-sub (multiple receivers of the same messages).
joshperry
source share