问题
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.)
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.
回答1:
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.
回答2:
You should check out ZeroMQ. It has a simpler interface than pure BSD sockets, it more portable and has excellent documentation.
回答3:
Checkout networkComms.net for an open source network communication library.
回答4:
It sounds like you need a message queue.
There are many, many solutions, of which just one is redis: http://redis.io
来源:https://stackoverflow.com/questions/8952837/how-to-do-simple-reliable-network-messaging