简体   繁体   中英

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

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!

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.

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.

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.

I am looking at the Remote Call Framework , for my purely C++ apps. The specs look pretty and promising. I am going to try it.

mmm - DLLs are not processes, so I'm assuming you mean IPC between your Java app, and some other native application that is linked to the DLL. Sockets, for certain, are the way to go here. It will make everything easier for you.

Another option would be to use JNI to talk to a DCOM implementation, but I don't think you'll gain much (other than having to deal with the headaches of COM and JNI :-) ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM