本地 C++ 之间的通信有哪些好的选择?和Java程序?

发布于 2024-09-26 17:21:55 字数 1149 浏览 0 评论 0原文

我所说的“本地”是指两者都在同一子网中运行,在大多数情况下是同一主机/VM,因此一些标准的跨网络跨平台 RPC 机制(如 SOAP、XML-RPC、CORBA 等)似乎没有必要。

有效负载主要是从 C++ 到 Java 的数字(大部分是表格)数据以及一些少量的元数据(例如可用的数据服务、数据描述/类型等),以及从 Java 到 C++ 的控制台/脚本化 UI 事件。因此,C++ 程序充当服务器,而 Java 程序充当客户端。

我可以列举几个选项(主要来自搜索这个精彩的网站),但我从未在现实世界的重型情况下使用或见过一个选项,所以我真的希望“去过那里,做过那件事”的人可以教育我有关选项的优点和缺点。

  1. 共享内存
  2. 管道、stdin/stdout 等。
  3. 通过普通套接字(可能是 UDP)的自定义数据结构(这个问题
  4. 通过普通套接字的消息,可以是 Google 协议缓冲区、Thrift、JSON 等(这个答案等)
  5. Java RMI 与 C++ RMI 服务器(这个问题
  6. JNI(这个问题

我很确定我错过了很多选择。谢谢大家的帮助!


编辑:我忘了提到性能不是一个主要问题,因为数据吞吐量预计不会很大(服务器很大程度上受数据库限制),但了解一个选项是否更快或更慢很重要。例如,我认为没有什么比共享内存更好的了(如果做得正确的话)。

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.

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++. So the C++ program acts like the server and Java program the client.

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.
  3. Custom data structure over plain socket (probably UDP) (this question)
  4. Messages over plain socket, could be Google protocol buffer, Thrift, JSON, etc. (this answer, among others)
  5. Java RMI with C++ RMI server (this question)
  6. JNI (some answers in this question)

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

つ低調成傷 2024-10-03 17:21:55

选项 3 和 4 用于现实世界的重载情况。

选项 1、2、6 不会到达另一台主机。

选项 5 对于非 Java 端来说可能太麻烦了。

我会选择选项 4,因为选项 3 的级别太低(除非选项 4 速度太慢)。从您列举的协议中选择您最喜欢的跨平台轻量级消息传递协议。这些都是经过“实战考验”的,并且拥有适用于大多数语言的库。

Options 3 and 4 are used in real-world heavy-duty situations.

Options 1,2,6 do not reach another host.

Option 5 is probably too troublesome for the non-Java side.

I'd go with Option 4, because Option 3 is too low-level (unless Option 4 turns out to be too slow). 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.

毁虫ゝ 2024-10-03 17:21:55

我会选择选项 4。我会跳过选项 5。2 会很笨重。

我们正在谈论以纯文本形式传递数字,是吗?

I'd go with option 4. I'd skip 5. 2 would be clunky.

We're talking passing the numerics as plain text, yes?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文