Reputation: 261
When sending async data in a socket with Socket.BeginSend()
, this will send data to the conneted client or server, now this works fine, but now when i pulled out the network cable and send something again, it does not give away any error,
Socket.EndSend()
does not throw an exceptionnow i know that it is no guarantee that the data has been send when a sendCallback happens becouse of buffering but how can i check if the data that has been send actualy has been send and received?
Upvotes: 1
Views: 4477
Reputation: 16761
TCP/IP cannot guarantee that all data that have been sent will also be received. But even if it would guarantee it that is not what you need. What sender actually needs is to know if it does not have to send data again, and that usually implies if sent data has been processed on receivers side.
If sender needs to know this then communication protocol must be changed so that sender can receive a confirmation by the receiver that it can safely assume that data has been processed. Also, sender must at certain point proclaim a time-out (and close the socket) if receiver did not send back the confirmation on time (and in your code you must decide what to do about it, maybe save data to be sent at later time, or raise an alert to the user). Also receiver must handle the situation where the same data is being sent twice (as last item in previous connection, and as another item in new connection) and not treat this data as two distinct pieces of data.
I can elaborate more on each of these "musts" if required. Communication is hard.
Upvotes: 3