Windows OS环境下C++应用程序与Java应用程序的进程间通信

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1209406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:54:23  来源:igfitidea点击:

Interprocess Communication between C++ app and Java App in Windows OS environment

javac++windowsipc

提问by David Coufal

We have a C++ application on Windows that starts a java process. These two apps need to communicate with each other (via snippets of xml).

我们在 Windows 上有一个 C++ 应用程序,它启动一个 java 进程。这两个应用程序需要相互通信(通过 xml 片段)。

What interprocess communication method would you choose, and why?

您会选择哪种进程间通信方法,为什么?

Methods on the table for us are: a shared file(s), pipes and sockets (although I think this has some security concerns). I'm open to other methods.

可供我们使用的方法是:共享文件、管道和套接字(尽管我认为这有一些安全问题)。我对其他方法持开放态度。

回答by oxbow_lakes

I'm not sure why you think socket-based communication would have security concerns (use SSL). It is often a very good approach as it is language agnostic, assuming that you have a well-defined communication protocol. Have a look at Google's protocol buffers, for example - they generate the required Java classes and streams.

我不确定您为什么认为基于套接字的通信会有安全问题(使用 SSL)。它通常是一种非常好的方法,因为它与语言无关,假设您有一个明确定义的通信协议。例如,看看 Google 的协议缓冲区- 它们生成所需的 Java 类和流。

In my experience, file systems (especially network file systems) are not well suited to such communication as they are not necessarily tuned for messaging(I've seen caching issues result in files being not picked up by the target process for example).

根据我的经验,文件系统(尤其是网络文件系统)不太适合这种通信,因为它们不一定适合消息传递(例如,我已经看到缓存问题导致目标进程无法获取文件)。

Another option is a messaginglayer (AMQor Tibco for example) although this will likely involve a greater administrative overhead (plus expertise) to set up.

另一种选择是消息传递层(例如AMQ或 Tibco),尽管这可能会涉及更大的管理开销(加上专业知识)来设置。

Personally I would opt for a pure-socket approach because of its flexibility and simplicity. You will be in complete control.

我个人会选择纯套接字方法,因为它的灵活性和简单性。您将完全掌控

回答by Ron Warholic

I've used named pipes for communication between C# and a cross-platform c++ app and had nothing but good results. Barring that sockets is definitely the way to go.

我使用命名管道在 C# 和跨平台 C++ 应用程序之间进行通信,但结果很好。除非那个套接字绝对是要走的路。

回答by patros

Sockets are nice. They give you the ability to very easily create a blackbox testing layer around each component, as well as run each component on its own machine.

插座很好。它们使您能够非常轻松地围绕每个组件创建一个黑盒测试层,以及在自己的机器上运行每个组件。

Security is definitely a concern, but there are a good range of options depending on how important it is. You can use SSL, custom handshaking, password protected logins and firewalls to help secure it.

安全绝对是一个问题,但有很多选择,具体取决于它的重要性。您可以使用 SSL、自定义握手、密码保护登录和防火墙来帮助保护它。

Edit: Not something I'd recommend, but there's also shared memory using JNI. Just thought I'd mention it because it's not on your list.

编辑:不是我推荐的东西,但也有使用 JNI 的共享内存。只是想我会提到它,因为它不在您的列表中。

回答by Draemon

Iceis pretty cool :)

很酷:)