What is the best approach for IPC between Java and C++?

12,271

Solution 1

I'd use a standard TCP/IP socket, where the app listens on some port and the library connects to it to report what it has to report and expect the answers.

The abstraction is robust, well supported and will have no interop issues.

Solution 2

Have you considered Facebook's Thrift framework?

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.

Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages.

It can work over TCP sockets and the serialization/deserialization is already built-in.

Read the whitepaper for details.

Solution 3

Google protocol buffer can help you serialize data in a language and platform neutral way. It will also generate code in Java and C++ to handle reading and writing the serialized data. You can then use any communication mechanism you wish to send the data. For example, you could send it over a TCP socket or via shared memory IPC.

Share:
12,271
Admin
Author by

Admin

Updated on June 23, 2022

Comments

  • Admin
    Admin almost 2 years

    I would like to implement a robust IPC solution between a single JVM app (one process, potentially multiple threads) and a native C++ application that is linked to a C++ dll. The dll may or may not be on the same physical machine. What is the best approach for doing so?

    Any suggestions will be greatly appreciated! Thanks!

  • Admin
    Admin over 15 years
    Thrift would be great, but I see the first sentence in their docs here say it won't work on Windows...am I interpreting that correctly? wiki.apache.org/thrift/ThriftInstallationWin32
  • dalle
    dalle about 13 years
    @Justin: Yes, it does not compile using Visual Studio.
  • Kevin Shea
    Kevin Shea over 11 years
    Older thread, but thrift now ships with Visual Studio (2010) projects included