简体   繁体   English

本地C ++和Java程序之间的通信有哪些好的替代方案?

[英]What are the good alternatives for communication between local C++ and Java programs?

By "local" I mean both run in the same subnet, in most cases the same host/VM, therefore some standard cross-network cross-platform RPC mechanisms like SOAP, XML-RPC, CORBA, etc. seem unnecessary. “本地”是指两者都在同一子网中运行,在大多数情况下是相同的主机/ VM,因此一些标准的跨网络跨平台RPC机制(如SOAP,XML-RPC,CORBA等)似乎是不必要的。

The payload is mainly numerical (mostly tabulated) data with some small amount of meta data (for example available data services, data description/type, etc.) from C++ to Java, and console/scripted UI events from Java to C++. 有效载荷主要是数字(主要是表格)数据,包含从C ++到Java的少量元数据(例如可用数据服务,数据描述/类型等),以及从Java到C ++的控制台/脚本化UI事件。 So the C++ program acts like the server and Java program the client. 因此,C ++程序就像客户端的服务器和Java程序一样。

I can enumerate several options (mostly from searching this wonderful site) but I've never used or seen one in a real-world heavy-duty situation, so I really hope someone who's "been there, done that" can educate me about the pros and cons of the options. 我可以列举几个选项(主要来自搜索这个精彩的网站),但我从来没有在真实世界的重型场景中使用或看过一个,所以我真的希望有人“在那里,做到这一点”可以教育我关于选项的利弊。

  1. Shared memory 共享内存
  2. Pipe, stdin/stdout, etc. 管道,stdin / stdout等
  3. Custom data structure over plain socket (probably UDP) ( this question ) 普通套接字上的自定义数据结构(可能是UDP)( 这个问题
  4. Messages over plain socket, could be Google protocol buffer, Thrift, JSON, etc. ( this answer , among others) 普通套接字上的消息可能是Google协议缓冲区,Thrift,JSON等( 此答案等)
  5. Java RMI with C++ RMI server ( this question ) 带有C ++ RMI服务器的Java RMI( 这个问题
  6. JNI (some answers in this question ) JNI( 这个问题的一些答案)

I'm pretty sure I've missed many options. 我很确定我错过了很多选择。 Thank you all for your help! 感谢大家的帮助!


Edited: I forgot to mention that performance is not a major concern as the data throughput is not expected to be huge (server is heavily database-bound), but it would be important to know if one option stands out to be much faster or slower. 编辑:我忘了提到性能不是一个主要问题,因为数据吞吐量预计不会很大(服务器严重受数据库限制),但重要的是要知道一个选项是否更快或更慢。 For example, I suppose nothing beats shared memory (if done right). 例如,我认为没有什么比共享内存更好(如果做得对)。

Options 3 and 4 are used in real-world heavy-duty situations. 选项3和4用于现实世界的重载情况。

Options 1,2,6 do not reach another host. 选项1,2,6没有到达另一个主机。

Option 5 is probably too troublesome for the non-Java side. 对于非Java方面,选项5可能太麻烦了。

I'd go with Option 4, because Option 3 is too low-level (unless Option 4 turns out to be too slow). 我选择选项4,因为选项3太低级别(除非选项4太慢)。 Choose your favourite cross-platform light-weight messaging protocol from the ones you enumerated. 从您列举的那些中选择您最喜欢的跨平台轻量级消息传递协议。 Those are all "battle-tested" and have libraries for most languages. 这些都是“经过实战考验”并且拥有大多数语言的库。

I'd go with option 4. I'd skip 5. 2 would be clunky. 我会选择4.我会跳过5. 2会很笨重。

We're talking passing the numerics as plain text, yes? 我们正在谈论将数字作为纯文本传递,是吗?

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

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