4

Suppose I have a UDP socket and send a msg to the server. Now how to figure out if the msg has been received by the server?

Coded acknowledgment from server is a trivial option, is there any other way to find out? I guess no..

paper.plane
  • 1,201
  • 10
  • 17
  • 2
    Include some checksum in your message and make your server send a response. But wait...Isn't it writing TCP all over again? – zubergu Feb 20 '15 at 08:21
  • 1
    The obvious way would be to have the server send an acknowledgement. Can you indicate what that is not an option? – Mike Wise Feb 20 '15 at 08:21
  • Coded acknowledgment from server is a trivial option, is there any other way to find out? I guess no.. – paper.plane Feb 20 '15 at 08:25
  • 1
    That's the whole point of UDP : you can't be sure if datagrams arrived in the right order, or even if they arrived at all. Switch to TCP ? – Nicolas Repiquet Feb 20 '15 at 08:32

1 Answers1

4

You can never be sure that a message arrives, even with TCP not. That is a general limitation of communication networks (also applies to snail mail, for example). You can start with the Bizantine Generals Problem if you want to know more.

The thing you can do, is to increase the likelihood of detecting a message loss. Usually that is done be sending an acknowledgement to the sender. But that may get lost too, so for 100% reliability, you would need to send an acknowledgement for the acknowledgement. And then an acknowledgement for the acknowledgement's acknowledgement. And so on.

My advice: Use TCP, if reliability is your main concern. It has been around for some time, and probably won't have some of the flaws a custom solution would have. If you don't need the reliability of TCP, but need low latencies or something else UDP is good at, use UDP. In that case better make sure that it is not a problem if some packets get lost.

Jost
  • 5,948
  • 8
  • 42
  • 72