简体   繁体   English

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

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

We have a C++ application on Windows that starts a java process. 在Windows上,我们有一个C ++应用程序来启动Java进程。 These two apps need to communicate with each other (via snippets of xml). 这两个应用程序需要相互通信(通过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. 我愿意接受其他方法。

I'm not sure why you think socket-based communication would have security concerns (use SSL). 我不确定为什么您认为基于套接字的通信会带来安全隐患(使用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. 例如,看看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 messaging layer ( AMQ or 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 . 您将完全处于控制之中

I've used named pipes for communication between C# and a cross-platform c++ app and had nothing but good results. 我已经使用命名管道在C#和跨平台的c ++应用程序之间进行通信,但没有什么好结果。 Barring that sockets is definitely the way to go. 禁止使用套接字绝对是必经之路。

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. 编辑:我不建议这样做,但是也有使用JNI的共享内存。 Just thought I'd mention it because it's not on your list. 只是以为我会提到它,因为它不在您的列表中。

很酷:)

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

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