Any good and simple RPC library for interprocess calls?

I need to send a (possibly one) simple one-way command from client processes to a server process with arguments to C ++ built-in types (so serialization is pretty simple). C ++, Windows XP +.

I am looking for a library that does not require complex configuration, provides a simple interface, does not require from several hours to several days of training and does not have commercial restrictions on use. A simple solution for a simple task.

Boost.Interprocess is too low level for this simple task because it does not provide an RPC interface. Outlets are probably too crowded because I do not need to communicate between machines. The same goes for DCOM, CORBA, etc. Named pipes? Never used them, any good library on top of WinAPI? OpenMPI?

+44
c ++ rpc interprocess
Mar 22 2018-11-22T00:
source share
12 answers

I don’t think sockets really go too far. All alternatives have their problems, and sockets are much better supported than named pipes, shared memory, etc., because almost everyone uses them. Socket speed on the local system is probably not a problem.

There Apache Thrift:

http://incubator.apache.org/thrift/

There are several RPC implementations wrapped around the Google protobuf library as a marshaling mechanism:

https://github.com/google/protobuf/blob/master/docs/third_party.md#rpc-implementations

There XML-RPC:

http://xmlrpc-c.sourceforge.net/

If your messages are really simple, I can consider using UDP packets, then there are no connections for management.

+14
Mar 23 '11 at 0:20
source share

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"); 
+9
Mar 25 '11 at 20:24
source share

If you only need Windows support, I would use the built-in RPC for Windows, I wrote two introductory articles about this:

http://www.codeproject.com/KB/IP/rpcintro1.aspx
http://www.codeproject.com/KB/IP/rpcintro2.aspx

You can use the ncalrpc protocol if you need only local interprocess communication.

+5
Mar 29 '11 at 19:41
source share

Boost.mpi . Simple, fast, scalable.

 #include <boost/mpi/environment.hpp> #include <boost/mpi/communicator.hpp> #include <iostream> #include <sstream> namespace mpi = boost::mpi; int main(int argc, char* argv[]) { mpi::environment env(argc, argv); mpi::communicator world; std::stringstream ss; ss << "Hello, I am process " << world.rank() << " of " << world.size() << "."; world.send(1, 0, ss.str()); } 
+4
Mar 31 '11 at 20:29
source share

You probably don't even need a library. Windows has an IPC mechanism built into its core APIs (windows.h). You can send a Windows message to the message queue in the main window of different processes. Windows even defines a standard message to do just that: WM_COPYDATA.




The sending process basically does:

Reception process (window):

+2
Mar 30 2018-11-11T00:
source share

I know that we are far from easy to use. But of course you can stick with CORBA. For example. ACE / TAO

+2
Mar 31 '11 at 15:38
source share

If you only work with windows and really need a C ++ interface, use COM / DCOM. It is based on RPC (in turn, based on DCE RPC).

This is an extremely simple use - provided that you take the time to learn the basics.

+2
Apr 02 2018-11-11T00:
source share

I am told that RPC with Raknet is nice and simple.

+1
Mar 22 '11 at 23:17
source share

Alternatively, you can view msgpack-rpc

Update

Although Thrift / Protobuf is more flexible, I think, but there is a need to write code in a specific format. For example, Protobuf needs some .proto file that can be compiled with a specific compiler from a package that generates some classes. In some cases, other parts of the code may be more complicated. msgpack-rpc is much simpler. This does not require writing additional code. Here is an example:

 #include <iostream> #include <msgpack/rpc/server.h> #include <msgpack/rpc/client.h> class Server: public msgpack::rpc::dispatcher { public: typedef msgpack::rpc::request request_; Server() {}; virtual ~Server() {}; void dispatch(request_ req) try { std::string method; req.method().convert(&method); if (method == "id") { id(req); } else if (method == "name") { name(req); } else if (method == "err") { msgpack::type::tuple<> params; req.params().convert(&params); err(req); } else { req.error(msgpack::rpc::NO_METHOD_ERROR); } } catch (msgpack::type_error& e) { req.error(msgpack::rpc::ARGUMENT_ERROR); return; } catch (std::exception& e) { req.error(std::string(e.what())); return; } void id(request_ req) { req.result(1); } void name(request_ req) { req.result(std::string("name")); } void err(request_ req) { req.error(std::string("always fail")); } }; int main() { // { run RPC server msgpack::rpc::server server; std::auto_ptr<msgpack::rpc::dispatcher> dispatcher(new Server); server.serve(dispatcher.get()); server.listen("0.0.0.0", 18811); server.start(1); // } msgpack::rpc::client c("127.0.0.1", 18811); int64_t id = c.call("id").get<int64_t>(); std::string name = c.call("name").get<std::string>(); std::cout << "ID: " << id << std::endl; std::cout << "name: " << name << std::endl; return 0; } 

Exit

 ID: 1 name: name 

More complex examples can be found here https://github.com/msgpack/msgpack-rpc/tree/master/cpp/test

+1
Jan 04 '13 at 11:38
source share

I am using XmlRpc C ++ for Windows found here

Really easy to use :) But the only side effect is that this is only a client!

0
Mar 31 '11 at 9:03
source share

There is also Microsoft Messaging Queuing , which is pretty easy to use when all the processes are on the local machine.

0
Apr 02 2018-11-14T00:
source share

The simplest solution for interprocess communication is to use a file system. Requests and responses can be recorded as temporary files. You can develop a naming convention for request and response files.

This will not give you better performance, but perhaps it will be good enough.

-2
Mar 30 '11 at 10:41
source share



All Articles