Reputation: 350
Let's assume I am connected to someone using a System.Net.Sockets.TcpClient. I send a message to them, then I immediately call TcpClient.Close(); Is the other client guaranteed to get the message? Also, is this true/false in most TCP implementations?
Upvotes: 0
Views: 594
Reputation: 3360
Vlad's comment is correct - the delivery is not guaranteed.
Assume the TCP connection with a peer is established. The send operation just copy the data to the network stack in the operating system and it is OS responsibility to send it. The you call operation close. OS does not stop sending the previous data. OS postpone the socket close till data is sent. It is transparent from the application point of view.
But something wrong may happen. The peer may crash, network may have an outage or whatever. Although the OS tries to retransmit data if TCP ACK is not received the retrasmission may fail again and again till OS gives up. This general mechanism is the same in all OS implementing TCP protocol.
If you need guaranteed delivery then you must implement an application level mechanism to acknowledge received data.
Upvotes: 1