Reputation: 2465
I'm relatively new to C# so please bear with me.
I'm writing a TCP client server application and I must ensure that all messages that the client sends get delivered to the server. Client will send data and server will send back an ACK (implemented on the application level).
I know that the network layer ensures (or throws exception) that the endpoint computer receives data.
What I want to know is if there is a possibility that server computer receives data from client, but data doesn't get delivered to the server application (if there is nothing wrong with the server application).
Thank you for your answers.
Upvotes: 1
Views: 275
Reputation: 71565
The TCP protocol handles most cases of lost/dropped/collided packets, so you do not need to handle this at the code level. However, you DO need to handle cases of connection/communication timeouts, transport-level errors, etc. These are thrown out of the .NET Sockets library as exceptions, which will crash the whole application if you do not catch and handle them. The usual error-handling for these exceptions is simply to retry the connection.
Upvotes: 2
Reputation: 8639
This shouldn't happen, but weird things happen under high load and low memory.
The best way to cater for this approach is to include a sequence number in messages from client->server.
If a client doesn't receive an ACK, it can resend with the old sequence number; if the server has already received a message with the same sequence number, it can ignore it.
Upvotes: 3