You might like ZeroMQ for something similar. Perhaps this is not so much a complete RPC as the original messaging package you can use to create an RPC. It is simple, lightweight and impressive. You can easily implement RPC on top of it. Here is an example server directly from the manual:
// // Hello World server in C++ // Binds REP socket to tcp://*:5555 // Expects "Hello" from client, replies with "World" // #include <zmq.hpp> #include <unistd.h> #include <stdio.h> #include <string.h> int main () { // Prepare our context and socket zmq::context_t context (1); zmq::socket_t socket (context, ZMQ_REP); socket.bind ("tcp://*:5555"); while (true) { zmq::message_t request; // Wait for next request from client socket.recv (&request); printf ("Received Hello"); // Do some 'work' sleep (1); // Send reply back to client zmq::message_t reply (5); memcpy ((void *) reply.data (), "World", 5); socket.send (reply); } return 0; }
This example uses tcp: //*.5555, but uses more efficient IPC methods if you use:
socket.bind("ipc://route.to.ipc");
or even faster inter thread protocol:
socket.bind("inproc://path.for.client.to.connect");
Imbrondir Mar 25 '11 at 20:24 2011-03-25 20:24
source share