8.7 Lost Datagrams
Our UDP client/server example is not reliable.
If a client datagram is lost (say it is discarded by some router
between the client and server), the client will block forever in
its call to recvfrom in the function dg_cli,
waiting for a server reply that will never arrive. Similarly, if
the client datagram arrives at the server but the server's reply is
lost, the client will again block forever in its call to
recvfrom. A typical way to prevent this is to place a
timeout on the client's call to recvfrom. We will discuss
this in Section 14.2.
Just placing a timeout on the recvfrom
is not the entire solution. For example, if we do time out, we
cannot tell whether our datagram never made it to the server, or if
the server's reply never made it back. If the client's request was
something like "transfer a certain amount of money from account A
to account B" (instead of our simple echo server), it would make a
big difference as to whether the request was lost or the reply was
lost. We will talk more about adding reliability to a UDP
client/server in Section 22.5.
|