Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are sockets reliable?

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.

like image 965
not-exactly-a-unixhater Avatar asked Jul 21 '09 07:07

not-exactly-a-unixhater


3 Answers

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.

like image 173
Stephen C Avatar answered Sep 21 '22 16:09

Stephen C


Sockets are as reliable as you make your implementation, and based upon the underlying hardware. If you don't want the hassle of making a guaranteed delivery service (under what conditions? 100% is never going to happen), a message queue system is a good bet. The message queue will have implemented all of the persistence, queueing, retries, etc which you would need to implement yourself if you went with standard sockets.

like image 45
Yann Ramin Avatar answered Sep 23 '22 16:09

Yann Ramin


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.

like image 37
Fredrik Avatar answered Sep 20 '22 16:09

Fredrik