跨平台IPC

发布于 2024-07-04 19:12:37 字数 1448 浏览 5 评论 0原文

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

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

发布评论

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

评论(15

深爱不及久伴 2024-07-11 19:12:38

如果您愿意尝试一些不同的东西,可以使用 ICE 平台http://zeroc.com" rel="nofollow noreferrer">ZeroC。 它是开源的,几乎支持您能想到的所有操作系统,并且还支持 C++、C#、Java、Ruby、Python 和 PHP。 最后,它非常容易驱动(语言映射经过定制以自然地适合每种语言)。 它也快速高效。 甚至还有针对设备的精简版本。

If you're willing to try something a little different, there's the ICE platform from ZeroC. It's open source, and is supported on pretty much every OS you can think of, as well as having language support for C++, C#, Java, Ruby, Python and PHP. Finally, it's very easy to drive (the language mappings are tailored to fit naturally into each language). It's also fast and efficient. There's even a cut-down version for devices.

相权↑美人 2024-07-11 19:12:38

分布式计算通常很复杂,建议您使用现有的库或框架,而不是重新发明轮子。 上一篇文章已经列举了其中几个库和框架。 根据您的需要,您可以选择非常低级别(如套接字)或高级框架(如 CORBA)。 不可能有一个通用的“使用这个”答案。 您需要对分布式编程进行自我教育,然后会发现为工作选择合适的库或框架要容易得多。

有一个广泛使用的分布式计算 C++ 框架,称为 ACE 和 CORBA ORB TAO(基于 ACE 构建)。 有关于 ACE 的非常好的书籍 http://www.cs.wustl.edu/~ schmidt/ACE/ 所以你可以看一下。 小心!

Distributed computing is usually complex and you are well advised to use existing libraries or frameworks instead of reinventing the wheel. Previous poster have already enumerated a couple of these libraries and frameworks. Depending on your needs you can pick either a very low level (like sockets) or high level framework (like CORBA). There can not be a generic "use this" answer. You need to educate yourself about distributed programming and then will find it much easier to pick the right library or framework for the job.

There exists a wildly used C++ framework for distributed computing called ACE and the CORBA ORB TAO (which is buildt upon ACE). There exist very good books about ACE http://www.cs.wustl.edu/~schmidt/ACE/ so you might take a look. Take care!

回忆躺在深渊里 2024-07-11 19:12:38

到本地主机 FTW 的 TCP 套接字。

TCP sockets to localhost FTW.

梦毁影碎の 2024-07-11 19:12:38

它没有比使用管道更简单的了,我知道的每个操作系统都支持管道,并且几乎可以用每种语言访问。

查看 这个教程。

It doesn't get more simple than using pipes, which are supported on every OS I know of, and can be accessed in pretty much every language.

Check out this tutorial.

℡寂寞咖啡 2024-07-11 19:12:38

Python 有一个非常好的 IPC 库:请参阅 https://docs.python.org/2/library/ipc.html

Python has a pretty good IPC library: see https://docs.python.org/2/library/ipc.html

执手闯天涯 2024-07-11 19:12:38

Xojo 通过其 IPCSocket 类 内置了跨平台 IPC 支持。 尽管您显然无法用其他语言“实现”它,但您可以在 Xojo 控制台应用程序中使用它并从其他语言调用它,这使得此选项对您来说可能非常简单。

Xojo has built-in cross-platform IPC support with its IPCSocket class. Although you obviously couldn't "implement" it in other languages, you could use it in a Xojo console app and call it from other languages making this option perhaps very simple for you.

森罗 2024-07-11 19:12:38

当前,有一个非常简单、符合 C++1x、文档齐全、兼容 Linux 和 Windows 的开源“CommonAPI”库:CommonAPI C++

如果愿意的话,底层 IPC 系统是 D-Bus (libdbus) 或 SomeIP。 应用程序接口是使用简单且专为 Franca IDL 语言定制的指定的。

In the current ages there is available a very easy, C++1x compliant, well documented, Linux and Windows compatible, open-source "CommonAPI" library: CommonAPI C++.

The underlying IPC system is D-Bus (libdbus) or SomeIP if one wish. Application interfaces are specified using a simple and tailored for that Franca IDL language.

做个少女永远怀春 2024-07-11 19:12:37

就速度而言,最好的跨平台IPC机制是管道。 然而,这假设您希望在同一台机器上跨平台 IPC。 如果您希望能够与远程计算机上的进程进行通信,您将需要考虑使用套接字。 幸运的是,如果您至少谈论 TCP,套接字和管道的行为几乎相同。 虽然用于设置和连接它们的 API 不同,但它们的作用都类似于数据流。

然而,困难的部分不是沟通渠道,而是你通过它传递的消息。 您确实想看看能够为您执行验证和解析的东西。 我建议您查看 Google 的协议缓冲区。 您基本上创建一个规范文件来描述要在进程之间传递的对象,并且有一个编译器可以生成多种不同语言的代码,用于读取和写入与规范匹配的对象。 这比尝试自己提出消息传递协议和解析器要容易得多(并且不易出现错误)。

In terms of speed, the best cross-platform IPC mechanism will be pipes. That assumes, however, that you want cross-platform IPC on the same machine. If you want to be able to talk to processes on remote machines, you'll want to look at using sockets instead. Luckily, if you're talking about TCP at least, sockets and pipes behave pretty much the same behavior. While the APIs for setting them up and connecting them are different, they both just act like streams of data.

The difficult part, however, is not the communication channel, but the messages you pass over it. You really want to look at something that will perform verification and parsing for you. I recommend looking at Google's Protocol Buffers. You basically create a spec file that describes the object you want to pass between processes, and there is a compiler that generates code in a number of different languages for reading and writing objects that match the spec. It's much easier (and less bug prone) than trying to come up with a messaging protocol and parser yourself.

追我者格杀勿论 2024-07-11 19:12:37

对于 C++,请查看 Boost IPC
您也可以创建或找到一些脚本语言的绑定。

否则,如果能够与脚本语言交互真的很重要,那么最好的选择就是使用文件、管道或套接字,甚至是更高级别的抽象,例如 HTTP。

For C++, check out Boost IPC.
You can probably create or find some bindings for the scripting languages as well.

Otherwise if it's really important to be able to interface with scripting languages your best bet is simply to use files, pipes or sockets or even a higher level abstraction like HTTP.

背叛残局 2024-07-11 19:12:37

如果您想要一个便携、易于使用、多语言和 LGPLed 解决方案,我会推荐ZeroMQ

  • 速度快得惊人,几乎可以线性扩展,而且仍然很简单。
  • 适用于简单和复杂的系统/架构。
  • 提供非常强大的通信模式:REP-REP、PUSH-PULL、PUB-SUB、PAIR-PAIR。
  • 如果您在线程 (inproc://)、进程 (ipc:/ /)或机器({tcp|pgm|epgm}://),具有智能选项来剃除部分在 VMware 虚拟机之间运行连接时的协议开销 (vmci://)。

对于序列化,我建议使用 MessagePack 或 Protocol Buffers(其他也已经提到过),具体取决于您的需求。

If you want a portable, easy to use, multi-language and LGPLed solution, I would recommend you ZeroMQ:

  • Amazingly fast, almost linear scaleable and still simple.
  • Suitable for simple and complex systems/architectures.
  • Very powerful communication patterns available: REP-REP, PUSH-PULL, PUB-SUB, PAIR-PAIR.
  • You can configure the transport protocol to make it more efficient if you are passing messages between threads (inproc://), processes (ipc://) or machines ({tcp|pgm|epgm}://), with a smart option to shave off some part of the protocol overheads in case of connections are running between VMware virtual machines (vmci://).

For serialization I would suggest MessagePack or Protocol Buffers (which other have already mentioned as well), depending on your needs.

无法回应 2024-07-11 19:12:37

为什么不是D-Bus? 它是一个非常简单的消息传递系统,几乎可以在所有平台上运行,并且专为稳健性而设计。 目前几乎所有脚本语言都支持它。

http://freedesktop.org/wiki/Software/dbus

Why not D-Bus? It's a very simple message passing system that runs on almost all platforms and is designed for robustness. It's supported by pretty much every scripting language at this point.

http://freedesktop.org/wiki/Software/dbus

往日 2024-07-11 19:12:37

您可能想尝试 YAMI ,它非常简单但功能齐全,便携且附带与几种语言的绑定

You might want to try YAMI , it's very simple yet functional, portable and comes with binding to few languages

空袭的梦i 2024-07-11 19:12:37

我建议您使用 plibsys C 库。 它非常简单、轻量级且跨平台。 根据麻省理工学院许可发布。 它提供:

  • 命名的系统范围共享内存区域(System V、POSIX 和 Windows 实现);
  • 用于访问同步的命名系统范围信号量(System V、POSIX 和 Windows 实现);
  • 基于共享内存和信号量的命名系统范围共享缓冲区实现;
  • 支持 IPv4 和 IPv6(UNIX 和 Windows 实现)的套接字(TCP、UDP、SCTP)。

这是一个易于使用的库,具有非常好的文档。 由于它是用 C 编写的,因此您可以轻松地从脚本语言进行绑定。

如果需要在进程之间传递大型数据集(特别是速度至关重要时),最好使用共享内存来传递数据本身,并使用套接字来通知进程数据已准备好。 可以这样实现:

  • 一个进程将数据放入共享内存段,并通过套接字向另一个进程发送通知; 由于通知通常很小,因此时间开销很小;
  • 另一个进程收到通知并从共享内存段中读取数据; 之后,它会发送一个通知,表明数据已读回到第一个进程,以便它可以提供更多数据。

这种方法可以以跨平台的方式实现。

I can suggest you to use the plibsys C library. It is very simple, lightweight and cross-platform. Released under the MIT license. It provides:

  • named system-wide shared memory regions (System V, POSIX and Windows implementations);
  • named system-wide semaphores for access synchronization (System V, POSIX and Windows implementations);
  • named system-wide shared buffer implementation based on the shared memory and semaphore;
  • sockets (TCP, UDP, SCTP) with IPv4 and IPv6 support (UNIX and Windows implementations).

It is easy to use library with quite a good documentation. As it is written in C you can easily make bindings from scripting languages.

If you need to pass large data sets between processes (especially if speed is essential) it is better to use shared memory to pass the data itself and sockets to notify a process that the data is ready. You can make it as following:

  • a process puts the data into a shared memory segment and sends a notification via a socket to another process; as a notification usually is very small the time overhead is minimal;
  • another process receives the notification and reads the data from the shared memory segment; after that it sends a notification that the data was read back to the first process so it can feed more data.

This approach can be implemented in a cross-platform fashion.

煮茶煮酒煮时光 2024-07-11 19:12:37

Facebook 的 Thrift 怎么样?

Thrift 是一个用于可扩展跨语言服务开发的软件框架。 它将软件堆栈与代码生成引擎相结合,构建可在 C++、Java、Python、PHP、Ruby、Erlang、Perl、Haskell、C#、Cocoa、Smalltalk 和 OCaml 之间高效、无缝工作的服务。

How about Facebook's Thrift?

Thrift is a software framework for scalable cross-language services development. It combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, Smalltalk, and OCaml.

没有伤那来痛 2024-07-11 19:12:37

我想你会想要一些基于套接字的东西。

如果您想要 RPC 而不仅仅是 IPC,我会建议像 XML-RPC/SOAP 这样的东西,它通过 HTTP 运行,并且可以从任何语言使用。

I think you'll want something based on sockets.

If you want RPC rather than just IPC I would suggest something like XML-RPC/SOAP which runs over HTTP, and can be used from any language.

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