views:

3081

answers:

12
+12  Q: 

cross platform IPC

Hi,

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 are my options? 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.

Does anyone have any advice?

+5  A: 

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.

Brian R. Bondy
+3  A: 

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.

Swaroop C H
+3  A: 

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.

Maximilian
The tutorial link is broken, do you have another link, or some keywords we could use to track it down?
rcreswick
As far as I know there is no pipe api thats similar in Win32 and unix unless you use cygwin which isn't a very convenient option for most windows programs.
Laserallan
+1  A: 

TCP sockets to localhost FTW.

Geoffrey Chetwood
+5  A: 

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.

Douglas Leeder
+9  A: 

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.

Douglas Mayle
+1 for Protocol Buffers, really nice IPC/RPC alternative.
sharkin
+1 First time I have heard about Protocol Buffers. Will no doubt come in handy soon.
kerchingo
Are pipes the answer when you want to communicate with a process that is already started and running? For that, it should be sockets right?
donatello
+3  A: 

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.

Jason Etheridge
+3  A: 

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

+1 thats a new one for me and looks interesting.
RSabet
+5  A: 

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

apenwarr
"D-Bus is licensed to you under your choice of the Academic FreeLicense version 2.1, or the GNU General Public License version 2." - GPL may not suit.
Nick
A: 

Python has a pretty good IPC library: see http://docs.python.org/lib/ipc.html

Adam Rosenfield
+2  A: 

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!

lothar
+2  A: 

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

mloskot