Cross platform IPC

Cross PlatformIpc

Cross Platform Problem Overview


I'm looking for suggestions on possible IPC mechanisms that are:

  • Cross platform (Win32 and Linux at least)
  • Simple to implement in C++ as well as the most common scripting languages (perl, ruby, python, etc).
  • Finally, simple to use from a programming point of view!

What my options are? I'm programming under Linux, but I'd like what I write to be portable to other OSes in the future. I've thought about using sockets, named pipes, or something like DBus.

Cross Platform Solutions


Solution 1 - Cross Platform

In terms of speed, the best cross-platform IPC mechanism will be pipes. That assumes, however, that you want cross-platform IPC on the same machine. If you want to be able to talk to processes on remote machines, you'll want to look at using sockets instead. Luckily, if you're talking about TCP at least, sockets and pipes behave pretty much the same behavior. While the APIs for setting them up and connecting them are different, they both just act like streams of data.

The difficult part, however, is not the communication channel, but the messages you pass over it. You really want to look at something that will perform verification and parsing for you. I recommend looking at Google's Protocol Buffers. You basically create a spec file that describes the object you want to pass between processes, and there is a compiler that generates code in a number of different languages for reading and writing objects that match the spec. It's much easier (and less bug prone) than trying to come up with a messaging protocol and parser yourself.

Solution 2 - Cross Platform

For C++, check out Boost IPC.
You can probably create or find some bindings for the scripting languages as well.

Otherwise if it's really important to be able to interface with scripting languages your best bet is simply to use files, pipes or sockets or even a higher level abstraction like HTTP.

Solution 3 - Cross Platform

Why not D-Bus? It's a very simple message passing system that runs on almost all platforms and is designed for robustness. It's supported by pretty much every scripting language at this point.

http://freedesktop.org/wiki/Software/dbus

Solution 4 - Cross Platform

If you want a portable, easy to use, multi-language and LGPLed solution, I would recommend you ZeroMQ:

  • Amazingly fast, almost linear scaleable and still simple.
  • Suitable for simple and complex systems/architectures.
  • Very powerful communication patterns available: REP-REP, PUSH-PULL, PUB-SUB, PAIR-PAIR.
  • You can configure the transport protocol to make it more efficient if you are passing messages between threads (inproc://), processes (ipc://) or machines ({tcp|pgm|epgm}://), with a smart option to shave off some part of the protocol overheads in case of connections are running between VMware virtual machines (vmci://).

For serialization I would suggest MessagePack or Protocol Buffers (which other have already mentioned as well), depending on your needs.

Solution 5 - Cross Platform

You might want to try [YAMI][1] , it's very simple yet functional, portable and comes with binding to few languages

[1]: http://www.msobczak.com/prog/yami/ "YAMI"

Solution 6 - Cross Platform

How about Facebook's Thrift?

> Thrift is a software framework for scalable cross-language services development. It combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, Smalltalk, and OCaml.

Solution 7 - Cross Platform

I think you'll want something based on sockets.

If you want RPC rather than just IPC I would suggest something like XML-RPC/SOAP which runs over HTTP, and can be used from any language.

Solution 8 - Cross Platform

YAMI - Yet Another Messaging Infrastructure is a lightweight messaging and networking framework.

Solution 9 - Cross Platform

I can suggest you to use the plibsys C library. It is very simple, lightweight and cross-platform. Released under the LGPL. It provides:

  • named system-wide shared memory regions (System V, POSIX and Windows implementations);
  • named system-wide semaphores for access synchronization (System V, POSIX and Windows implementations);
  • named system-wide shared buffer implementation based on the shared memory and semaphore;
  • sockets (TCP, UDP, SCTP) with IPv4 and IPv6 support (UNIX and Windows implementations).

It is easy to use library with quite a good documentation. As it is written in C you can easily make bindings from scripting languages.

If you need to pass large data sets between processes (especially if speed is essential) it is better to use shared memory to pass the data itself and sockets to notify a process that the data is ready. You can make it as following:

  • a process puts the data into a shared memory segment and sends a notification via a socket to another process; as a notification usually is very small the time overhead is minimal;
  • another process receives the notification and reads the data from the shared memory segment; after that it sends a notification that the data was read back to the first process so it can feed more data.

This approach can be implemented in a cross-platform fashion.

Solution 10 - Cross Platform

If you're willing to try something a little different, there's the ICE platform from ZeroC. It's open source, and is supported on pretty much every OS you can think of, as well as having language support for C++, C#, Java, Ruby, Python and PHP. Finally, it's very easy to drive (the language mappings are tailored to fit naturally into each language). It's also fast and efficient. There's even a cut-down version for devices.

Solution 11 - Cross Platform

Distributed computing is usually complex and you are well advised to use existing libraries or frameworks instead of reinventing the wheel. Previous poster have already enumerated a couple of these libraries and frameworks. Depending on your needs you can pick either a very low level (like sockets) or high level framework (like CORBA). There can not be a generic "use this" answer. You need to educate yourself about distributed programming and then will find it much easier to pick the right library or framework for the job.

There exists a wildly used C++ framework for distributed computing called ACE and the CORBA ORB TAO (which is buildt upon ACE). There exist very good books about ACE http://www.cs.wustl.edu/~schmidt/ACE/ so you might take a look. Take care!

Solution 12 - Cross Platform

It doesn't get more simple than using pipes, which are supported on every OS I know of, and can be accessed in pretty much every language.

Check out this tutorial.

Solution 13 - Cross Platform

TCP sockets to localhost FTW.

Solution 14 - Cross Platform

Solution 15 - Cross Platform

Xojo has built-in cross-platform IPC support with its IPCSocket class. Although you obviously couldn't "implement" it in other languages, you could use it in a Xojo console app and call it from other languages making this option perhaps very simple for you.

Solution 16 - Cross Platform

In the current ages there is available a very easy, C++1x compliant, well documented, Linux and Windows compatible, open-source "CommonAPI" library: CommonAPI C++.

The underlying IPC system is D-Bus (libdbus) or SomeIP if one wish. Application interfaces are specified using a simple and tailored for that Franca IDL language.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThomiView Question on Stackoverflow
Solution 1 - Cross PlatformDouglas MayleView Answer on Stackoverflow
Solution 2 - Cross PlatformBrian R. BondyView Answer on Stackoverflow
Solution 3 - Cross PlatformapenwarrView Answer on Stackoverflow
Solution 4 - Cross PlatformPequeView Answer on Stackoverflow
Solution 5 - Cross PlatformBronekView Answer on Stackoverflow
Solution 6 - Cross PlatformSwaroop C HView Answer on Stackoverflow
Solution 7 - Cross PlatformDouglas LeederView Answer on Stackoverflow
Solution 8 - Cross PlatformmloskotView Answer on Stackoverflow
Solution 9 - Cross PlatformAlexander SaprykinView Answer on Stackoverflow
Solution 10 - Cross PlatformJason EtheridgeView Answer on Stackoverflow
Solution 11 - Cross PlatformlotharView Answer on Stackoverflow
Solution 12 - Cross PlatformMaximilianView Answer on Stackoverflow
Solution 13 - Cross PlatformGEOCHETView Answer on Stackoverflow
Solution 14 - Cross PlatformAdam RosenfieldView Answer on Stackoverflow
Solution 15 - Cross PlatformPaul LefebvreView Answer on Stackoverflow
Solution 16 - Cross PlatformbloodyView Answer on Stackoverflow