我们是否可以使用远程方法调用将 linux 中的 C++ 程序与充当服务器的 C# 程序通信?

Is it possible that we could communicate C++ program in linux to a C# program acting as server using Remote Method Invocation?

是否可以在linuxOS中的C++程序(客户端程序)运行与C#程序之间实现client/server通信(服务器程序)运行 在 Windows 中使用 RMI 实现?任何人都可以提出任何可能的方法...欢迎提供任何有用的参考

您还需要遵循 Google Protobuf. It is available with C++ and C# 的思路。

来自 MSDN

的类似回答

It does not matter if you send data from java,c++ or c#, when it goes over the network it's just 1s and 0s. It's a matter of what you do with it on the client/server side. So, be sure that the data that you receive corresponds with the structure that you have (that you want to deserialize to).

Sometimes you need to manually put the bits and bytes together to get it all working out. However, there is something called "Protobuff" that can help you get a common structure of the data that you send, google it and read all about it.

您可以使用套接字实现客户端服务器,serialize/deserialize它使用 protobuf。 (MSDN link 可能有助于解决问题)

在网络上工作时,重要的是 协议 ,而不是 client/server。

In telecommunications, a communications protocol is a system of rules that allow two or more entities of a communications system to transmit information via any kind of variation of a physical quantity. These are the rules or standard that defines the syntax, semantics and synchronization of communication and possible error recovery methods.

Source重点是我的。

因此,为了让您的 C++ 客户端和 C# 服务器通信,您需要选择或定义将用于通信的协议。

您的协议可以构建在另一个协议之上。例如,您可以将 HTTP 用于传输目的,并定义描述 HTTP 请求和响应主体中的消息应使用何种语法的协议。这会对您有所帮助,因为有许多现成的 HTTP 通信解决方案。

实际上,无论如何你都会基于另一个来构建你的协议。 HTTP 本身建立在 TCP 之上。您需要选择它是低级协议还是高级协议。它们各有利弊。

但是您必须自己处理客户端和服务器之间的消息传递。

作为替代方案,您可以使用一些远程过程调用(或 RPC)解决方案:

Remote procedure call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure to execute in another address space (commonly on another computer on a shared network) without the programmer explicitly coding the details for this remote interaction.

这意味着您只需遵循如何构建客户端和服务器的指南,所有通信都将被隐藏,看起来就像只是调用对象的方法。

Source

以下是可能的 RPC 解决方案的简短列表:

  • 带 DCOM 的组件对象模型。维基:COM,DCOM. MSDN: COM, DCOM.
  • 简单对象访问协议。 Wiki.
  • Windows 通信基础。 Wiki. MSDN. SO(感谢 Sanju link)。

总结:

你的客户端和服务器在不同的环境,使用不同的平台开发,这不是问题。您只需使用您自己的基于某种协议的消息传递系统或某种 RPC 系统在它们之间建立通信。

我认为消息传递库最适合这个。看看 ZMQ for instance; they have binding for many languages found here 所以你可能有一种语言的事件调度器和另一种语言的监听器。另请查看 apache thrift

CORBA 是一种 IPC 机制,它将提供您正在寻找的 RPC 机制。

这里是 link 描述 C# 服务器和 JAVA 客户端之间的通信。

http://iiop-net.sourceforge.net/dnAdderRmiClient.html

在我之前工作的其中一家公司,它被用于 c++ 和 java 程序在 client/server 模型中的通信。

他们使用了 ACE/TAO 个库的组合。

http://www.cs.wustl.edu/~schmidt/TAO.html

我建议您不要使用远程方法调用在客户端和服务器之间进行通信。在 19 世纪 90 年代我们曾经认为 RMI 是个好主意,但从那时起我们意识到计算机之间的通信有更好的方法。

最流行的方法是使用 Web 服务,而最简单的 Web 服务风格是 RESTful Web 服务。 (查找它们。)这样做的好处是根本不关心客户端的运行时环境是否看起来像服务器的运行时环境,就像您的设置一样,您的客户端是 C++ on Linux 并且您的服务器是 Windows.

上的 C#

Mozilla 的 XPCOM 可能是您的桥梁。还有 PyXPCOM。实际上,最简单的方法是拥有一个中间 VBox。因此,您在 linux 机器上 运行 一个 VBox 实例 (运行ning Windows),然后使用 VBox API(来自 C++)在 VBox 中发出命令。所以你最终得到

Linux <--xpCom--> VBox <--COM--> Windows

我们可以只编写一个 C# 程序来侦听来自特定端口的消息,然后编写另一个 C++ 客户端程序来向该端口写入消息 port.As 这样我们就可以与两个应用程序进行通信。