Does socket data need to be error corrected?
-
07-07-2019 - |
Question
When using socket communication in PHP, do I need to confirm if a message has been successfully received after sending each message? Or would the transport layer (TCP) take care of error detection and correction, ensuring successful delivery of any sent messages?
Solution
You don't need to worry about such things on this level. Once you write the data into an open socket, you can be sure that it will eventually arrive correctly (assuming there is a route between the end points). What you should take care of is the return values of socket functions. Check all return values of the socket_*
functions for a reliable communication.
OTHER TIPS
TCP handles error detection and correction as far as it goes. There isn't really such a thing as ensuring successful delivery (cf. backhoe fade), so there's some level at which you need to take into account the possibility that a message will not be delivered.
You can safely believe that the data has been successfully received if the php function does not point out any specific error.
"TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer" , so that's a yes to the latter.