Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast Cross Platform Inter Process Communication in C++

Tags:

c++

p2p

ipc

I'm looking for a way to get two programs to efficiently transmit a large amount of data to each other, which needs to work on Linux and Windows, in C++. The context here is a P2P network program that acts as a node on the network and runs continuously, and other applications (which could be games hence the need for a fast solution) will use this to communicate with other nodes in the network. If there's a better solution for this I would be interested.

like image 492
Stephen Cross Avatar asked Feb 07 '10 22:02

Stephen Cross


People also ask

What is the fastest interprocess communication?

Shared memory is the fastest form of interprocess communication. The main advantage of shared memory is that the copying of message data is eliminated. The usual mechanism for synchronizing shared memory access is semaphores.

Which method is used for inter-process communication?

Different ways of IPC are pipe, message passing, message queue, shared memory, direct communication, indirect communication and FIFO. It is important to obtain synchronization among processes in IPC to maintain data consistency. Semaphore and mutex are two ways to do so.

What is inter-process communication with example?

Inter-process communication (IPC) is a mechanism that allows processes to communicate with each other and synchronize their actions. The communication between these processes can be seen as a method of co-operation between them. Processes can communicate with each other through both: Shared Memory.

What is the lowest latency method for interprocess communication?

Our experiments re- veal that shared memory provides the lowest latency and highest throughput, followed by kernel pipes and lastly, TCP/IP sockets. However, the latency trends provide interesting in- sights into the construction of each mechanism.


2 Answers

boost::asio is a cross platform library handling asynchronous io over sockets. You can combine this with using for instance Google Protocol Buffers for your actual messages.

Boost also provides you with boost::interprocess for interprocess communication on the same machine, but asio lets you do your communication asynchronously and you can easily have the same handlers for both local and remote connections.

like image 179
villintehaspam Avatar answered Oct 31 '22 02:10

villintehaspam


I have been using ICE by ZeroC (www.zeroc.com), and it has been fantastic. Super easy to use, and it's not only cross platform, but has support for many languages as well (python, java, etc) and even an embedded version of the library.

like image 31
rcv Avatar answered Oct 31 '22 00:10

rcv