简体   繁体   English

如何进行简单,可靠的网络消息传递?

[英]How to do simple, reliable network messaging?

I'm using sockets for communication between various processes right now. 我现在正在使用套接字在各个进程之间进行通信。 Everything is running on the same machine, so there is no packet loss, and I also don't get read timeouts etc. The messages are typically small blobs of data (JSON, sometimes binary.) Now I want to do cross-machine communication. 一切都在同一台机器上运行,因此没有数据包丢失,而且我也没有收到读取超时等信息。消息通常是小的数据块(JSON,有时是二进制)。现在,我想进行跨机器通信。 The client/server connection usually looks like this: The client tells the server to start some processing (passing in the task description), the server does the work and communicates progress back, and the client can optionally send a terminate message inbetween. 客户端/服务器连接通常如下所示:客户端告诉服务器开始一些处理(传递任务描述),服务器完成工作并回传进度,客户端可以选择在两者之间发送终止消息。 Once finished, the server remains listening while the client is completely disconnected (ie the session is finished, starting a new task starts a new session.) 完成后,在客户端完全断开连接的同时,服务器仍在侦听(即,会话完成,开始新任务将启动新会话)。

How should I implement the communication? 我应该如何实现沟通? I can easily continue using sockets over the network, but my understanding is that I'll now need to add lots of error handling to identify when a message didn't get through and communicate that somehow back to the server. 我可以轻松地继续通过网络使用套接字,但是我的理解是,我现在需要添加许多错误处理,以识别消息何时没有通过并将其以某种方式传达给服务器。 All I want is just send(message, target) and rest assured that the complete message gets transmitted; 我想要的只是send(message, target)并放心完整的消息会被传输; plus some notification when the other side is dead. 当另一侧死亡时,再加上一些通知。 I've seen that there are a few libraries like zero-mq which claim to do exactly that but also much more, and I'm not sure if such a messaging library is actually necessary. 我已经看到有一些像zero-mq这样的库声称可以做到这一点,但还有更多,我不确定是否真的需要这样的消息传递库。 Is there some easy to use library out there to do some basic communication? 是否有一些易于使用的库可以进行一些基本的交流?

I'm using C++ & Python, and BSD style-licenses are definitely strongly preferred for libraries. 我使用的是C ++和Python,BSD样式许可绝对是库的首选。 The library should also be rather stable, as the communication part is nothing really crucial and I'd like to be able to stick with one solution. 库也应该相当稳定,因为通信部分并没有真正重要的意义,我希望能够坚持使用一种解决方案。

TCP guarantees all pagackes are passed to destination [It does the re-send for you if it didn't]. TCP保证所有小包都传递到目标[如果没有,它将为您重新发送]。 So, if you use it - it will probably take more time [compared to single machine], but correctness of msg transmissions remains. 因此,如果您使用它-与单机相比,可能会花费更多时间,但是msg传输的正确性仍然存在。

You should check out ZeroMQ . 您应该签出ZeroMQ It has a simpler interface than pure BSD sockets, it more portable and has excellent documentation. 与纯BSD插槽相比,它具有更简单的界面,更轻便的功能以及出色的文档资料。

签出networkComms.net以获取开源网络通信库。

It sounds like you need a message queue. 听起来您需要一个消息队列。

There are many, many solutions, of which just one is redis: http://redis.io 解决方案很多,其中只有一种是redis: http: //redis.io

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

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