简体   繁体   English

在 java 和 c++ 之间使用 Socket for IPC 的优缺点是什么?

[英]what is pros and cons of using Socket for IPC between java and c++?

I recently forced to find an IPC protocol that is best for communicate between java and c++.我最近被迫寻找最适合 java 和 c++ 之间通信的 IPC 协议。

I searched the SO for finding best protocol for this, I found socket is the best approach for this, in SO.我在 SO 中搜索为此寻找最佳协议,我发现套接字是 SO 中的最佳方法。 But I couldn't find any thing about its cons or pros of sockets. So I want to know pros of this protocol and also I want to know pros of other protocol vs socket to choose best protocol for my application.但是我找不到关于 sockets 的利弊的任何信息。所以我想知道这个协议的优点,也想知道其他协议与套接字的优点,以便为我的应用程序选择最佳协议。

It is very likely that my two applications running on a same machine.很有可能我的两个应用程序运行在同一台机器上。

Update I should first select my protocol then I can decide run it on which system configuration.更新我应该首先 select 我的协议然后我可以决定在哪个系统配置上运行它。

The best IPC method really depends on what type of communication you have: Message passing, ensuring mutual exclusive execution, sharing data are various IPC, but sockets isn't the solution for all 3.最好的 IPC 方法实际上取决于您拥有的通信类型:消息传递、确保互斥执行、共享数据是各种 IPC,但 sockets 并不是所有 3 种的解决方案。

Think about, or provide information what form the information has you want to pass between the applications.考虑或提供您希望在应用程序之间以何种形式传递信息的信息。 Perhaps you find a typical scenario (like producer-consumer problem).也许你会发现一个典型的场景(比如生产者-消费者问题)。

If you have a message-passing problem, comparable in principle to oldschool TCP services, sockets are a good idea because they are well-tested and easy to debug;如果您有消息传递问题,原则上与老式 TCP 服务相当,sockets 是个好主意,因为它们经过充分测试且易于调试; They provide full decoupling, yet running locally doesn't have drawbacks compared to pipes because the kernel can do the blocking of one application (sender or receiver) efficiently.它们提供完全解耦,但与管道相比,在本地运行没有缺点,因为 kernel 可以有效地阻止一个应用程序(发送方或接收方)。

Sockets can be UDP, TCP or Unix sockets. In any case you don't need a.network card for local IPC with sockets. Sockets can be UDP, TCP or Unix sockets. 无论如何你都不需要网卡用于sockets的本地IPC。

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

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