简体   繁体   中英

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. 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; 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?

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 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.

You should check out ZeroMQ . It has a simpler interface than pure BSD sockets, it more portable and has excellent documentation.

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

It sounds like you need a message queue.

There are many, many solutions, of which just one is redis: http://redis.io

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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