Are sockets reliable?

2019-02-16 23:23发布

Is it a good idea to use sockets to send data between two servers, or should I use something like MQ for moving data.

My questions: are sockets reliable, if I need once only/assured delivery of the data?

Are there any other solutions?

Thanks.

8条回答
在下西门庆
2楼-- · 2019-02-17 00:03

Sockets are an application level API for performing network communication. The reliability of sockets depends on the network protocol that you select when you create the socket. If you select TCP/IP, you will get "reliable" transfer ... up to a limit. If you select UDP/IP you will get "unreliable" transfer.

As stated in other answers, TCP ensures that you don't lose or corrupt data up to a point:

  1. if there is a long enough network outage, or the sender or receiver dies a TCP/IP connection will break and you will lose data unless you take steps to restart the connection.
  2. if there is a network level data corruption, there is a small probability that it won't be detected by the checksums.

For higher levels of reliability guarantees than TCP/IP provides, you need to implement more sensitive checksumming and guaranteed delivery mechanisms over the top of your application's Socket-based networking layer. Or use a message queuing product that does hard the work for you.

So the answer to your question is that it depends on how you use Sockets, and on what level of reliability your system requires.

查看更多
forever°为你锁心
3楼-- · 2019-02-17 00:05

You should probably use an MQ if you need guaranteed delivery no matter what happens (like if the other party goes offline for maintenance) and you don't want to write all the logic yourself. Sockets is what you use to connect to an other party, no matter if that party is the MQ or the final receiver of the message.

查看更多
登录 后发表回答