简体   繁体   English

Java 和 C++ 之间 IPC 的最佳方法是什么?

[英]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.我想在单个 JVM 应用程序(一个进程,可能是多个线程)和链接到 C++ dll 的本机 C++ 应用程序之间实现一个强大的 IPC 解决方案。 The dll may or may not be on the same physical machine. dll 可能位于也可能不在同一台物理机器上。 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. 我使用标准的TCP / IP套接字,应用程序监听某个端口,并且库连接到它以报告它必须报告的内容并期望得到答案。

The abstraction is robust, well supported and will have no interop issues. 抽象是健壮的,得到很好的支持,并且没有互操作问题。

Have you considered Facebook's Thrift framework ? 你有没有考虑过Facebook的Thrift框架

Thrift is a software framework for scalable cross-language services development. Thrift是可扩展的跨语言服务开发的软件框架。 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. 它将软件堆栈与代码生成引擎相结合,以构建在C ++,Java,Python,PHP,Ruby,Erlang,Perl,Haskell,C#,Cocoa,Smalltalk和OCaml之间高效无缝工作的服务。

Thrift allows you to define data types and service interfaces in a simple definition file. Thrift允许您在简单的定义文件中定义数据类型和服务接口。 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. 将该文件作为输入,编译器生成用于轻松构建RPC客户端和服务器的代码,这些客户端和服务器可跨编程语言无缝通信。

It can work over TCP sockets and the serialization/deserialization is already built-in. 它可以在TCP套接字上工作,并且序列化/反序列化已经内置。

Read the whitepaper for details. 阅读白皮书了解详情。

Google protocol buffer can help you serialize data in a language and platform neutral way. Google协议缓冲区可以帮助您以语言和平台中立的方式序列化数据。 It will also generate code in Java and C++ to handle reading and writing the serialized data. 它还将生成Java和C ++代码,以处理读取和写入序列化数据。 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. 例如,您可以通过TCP套接字或通过共享内存IPC发送它。

I am looking at the Remote Call Framework , for my purely C++ apps. 我正在寻找远程调用框架 ,我的纯C ++应用程序。 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. mmm - DLL不是进程,所以我假设你的意思是你的Java应用程序和链接到DLL的其他一些本机应用程序之间的IPC。 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 :-) ). 另一个选择是使用JNI与DCOM实现交谈,但我认为你不会获得太多收益(除了必须处理COM和JNI的头痛:-))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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