我正在寻找一种网络服务,可以让我向选定的客户端发送消息

发布于 2024-10-24 17:26:00 字数 426 浏览 1 评论 0原文

我有一个程序将在网络上的多个设备上运行。这些程序需要在彼此之间发送数据 - 到指定的设备(不是所有设备)。

server = server.Server('192.168.1.10')

server.identify('device1')
server.send('device2', 'this will be pickled and sent to device2')

这是我需要做的一些基本示例代码。当然,它也需要接收。

当有人向我指出 MPI 的方向时,我正在考虑使用 Twisted 构建自己的简单消息传递服务器。我以前从未研究过 MPI 协议,该网站提供了相当模糊的示例。

MPI 是一个好方法吗?有更好的选择吗?

I have a program which will be running on multiple devices on a network. These programs will need to send data between each other - to specified devices (not all devices).

server = server.Server('192.168.1.10')

server.identify('device1')
server.send('device2', 'this will be pickled and sent to device2')

That's some basic example code for what I need to do. Of course, it will also need to receive.

I was looking at building my own simple message passing server using Twisted when someone pointed me in the direction of MPI. I've never looked into the MPI protocol before and that website gives rather vague examples.

Is MPI a good approach? Are there better alternatives?

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

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

发布评论

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

评论(4

帅哥哥的热头脑 2024-10-31 17:26:01

MPI 非常擅长在集群中的多台或多台机器上运行紧密耦合的程序进行通信。如果您正在运行非常松散耦合的程序 - 仅偶尔进行交互 - 或者机器比集群内的分布更分散,例如分散在 LAN 周围 - 那么 MPI 可能不是您想要的。

MPI is really good at doing the communications for running a tightly-coupled program accross several or many machines in a cluster. If you're running very loosely coupled programs - only interacting occasionally - or the machines are more distributed than within a cluster, like scattered around a LAN - then MPI is probably not what you're looking for.

薄凉少年不暖心 2024-10-31 17:26:01

有几个开源消息代理已经可以为您处理此类事情,并提供完整的 API 可供使用。

您应该看一下:

您可以自己构建它,但这就像重新发明轮子(旁注:在我开始查看现有解决方案之前,我实际上只意识到我正在构建一个消息代理 - 构建一个消息代理需要大量工作)。

There are several Open Source message brokers that already handle this kind of stuff for you, and come with a full API ready to use.

You should take a look at:

You could build it yourself, but that would be like reinventing the wheel (and on a side-note: I actually only realised I was half-way building a message broker before I started looking at existing solutions - building one takes a lot of work).

∝单色的世界 2024-10-31 17:26:01

考虑使用类似 ZeroMQ 的东西。它支持最有用的消息传递习惯用法 - 推/拉、发布/订阅等,尽管从您的问题中并不能 100% 清楚您需要哪一个,但我很确定您会找到在那里回答。

他们有一个很棒的这里的用户指南,以及Python 绑定 得到了很好的开发和支持。一些代码示例在这里

Consider using something like ZeroMQ. It supports the most useful messaging idioms - push/pull, publish/subscribe and so on, and although it's not 100% clear from your question which one you need, I'm pretty sure you will find the answer there.

They have a great user guide here, and the Python bindings are well-developed and supported. Some code samples are here.

御弟哥哥 2024-10-31 17:26:01

您可以实现 MPI 函数以在不同代码之间创建通信。在这种情况下,服务器程序应该公开具有不同ID的“MPI端口”。客户端应该寻找此端口并尝试连接到它们。只有服务器可以接受每次通信。一旦通信建立,代码就可以在它们之间交换数据。

另一种可能性是在多指令 MPI 选项中运行不同的程序。在这种情况下,所有程序都会同时执行,并且无需创建端口通信器。执行它们后,您可以在选择的程序组之间创建特定的通信器。

请告诉我你需要什么样的方法,我可以提供c代码来实现这些功能。

You can implement MPI functions in order to create a communication between different codes. In this case the server program should public "MPI ports" with differents IDs. Clients should look for this ports and try to connect to them. Only server can accept each communication. Once the communication is stablished, codes can exchange data between them.

Another posibility is to run different programs in Multiple Instruction MPI option. In this case all programs are executed at the same time, and there is not necessity to create port communicators. After they are executed, you can create particular communicators between groups of programms you select.

Please tell me what kind of method you need and I can provide c code to implement the functions.

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