如何进行简单,可靠的网络消息传递? [英] How to do simple, reliable network messaging?

查看:75
本文介绍了如何进行简单,可靠的网络消息传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用套接字在各个进程之间进行通信.一切都在同一台机器上运行,因此没有数据包丢失,而且我也没有收到读取超时等信息.消息通常是小的数据块(JSON,有时是二进制).现在,我想进行跨机器通信.客户端/服务器连接通常如下所示:客户端告诉服务器开始一些处理(传递任务描述),服务器完成工作并回传进度,客户端可以选择在两者之间发送终止消息.完成后,在客户端完全断开连接的情况下(即会话结束,开始新任务将启动新会话),服务器仍会监听.

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. 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 (i.e. the session is finished, starting a new task starts a new session.)

我应该如何实现沟通?我可以轻松地继续通过网络使用套接字,但是我的理解是,我现在需要添加许多错误处理,以识别何时消息没有通过并将消息以某种方式传达给服务器.我想要的只是send(message, target),请放心,完整的消息将被传输.当另一边死了时,再加上一些通知.我已经看到有一些像zero-mq这样的库声称可以做到这一点,但还有更多,我不确定是否真的需要这样的消息传递库.有一些易于使用的库可以进行一些基本的交流吗?

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; 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. Is there some easy to use library out there to do some basic communication?

我正在使用C ++& Python和BSD样式许可绝对是库的首选.库也应该相当稳定,因为通信部分并没有什么真正的关键,我希望能够坚持使用一种解决方案.

I'm using C++ & Python, and BSD style-licenses are definitely strongly preferred for libraries. 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 可以保证所有安全被传递到目的地[如果没有,它会为您重新发送].因此,如果您使用它-与单台计算机相比,可能会花费更多时间,但是msg传输的正确性仍然存在.

TCP guarantees all pagackes are passed to destination [It does the re-send for you if it didn't]. So, if you use it - it will probably take more time [compared to single machine], but correctness of msg transmissions remains.

这篇关于如何进行简单,可靠的网络消息传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆