UDP Response

11,275

Solution 1

You can never receive an error, or notice for a UDP packet that did not reach destination.

Solution 2

The sendto call didn't fail. The datagram was sent to the destination.

The recipient of the datagram or some router on the way to it might return an error response (host unreachable, port unreachable, TTL exceeded). But the sendto call will be history by the time your system receives it. Some operating systems do provide a way to find out this occurred, often with a getsockopt call. But since you can't rely on getting an error reply anyway since it depends on network conditions you have no control over, it's generally best to ignore it.

Sensible protocols layered on top of UDP use replies. If you don't get a reply, then either the other end didn't get your datagram or the reply didn't make it back to you.

Solution 3

"UDP is a simpler message-based connectionless protocol. In connectionless protocols, there is no effort made to set up a dedicated end-to-end connection. Communication is achieved by transmitting information in one direction, from source to destination without checking to see if the destination is still there, or if it is prepared to receive the information."

Solution 4

The machine to which you're sending packets may reply with an ICMP UDP port unreachable message.

Solution 5

The UDP protocol is implemented on top of IP. You send UDP packets to hosts identified by IP addresses, not MAC addresses.

And as pointed out, UDP itself will not send a reply, you will have to add code to do that yourself. Then you will have to add code to expect the reply, and take the proper action if the response is lost (typically resend on a timer, until you decide the other end is "dead"), and so on.

Share:
11,275
user3341101
Author by

user3341101

Updated on June 04, 2022

Comments

  • user3341101
    user3341101 almost 2 years

    UDP doesnot sends any ack back, but will it send any response?

    I have set up client server UDP program. If I give client to send data to non existent server then will client receive any response?

    My assumption is as;

    Client -->Broadcast server address (ARP) Server --> Reply to client with its mac address(ARP) Client sends data to server (UDP)

    In any case Client will only receive ARP response. If server exists or not it will not get any UDP response?

    Client is using sendto function to send data. We can get error information after sendto call.

    So my question is how this info is available when client doesn't get any response. Error code can be get from WSAGetLastError.

    I tried to send data to non existent host and sendto call succeeded . As per documentation it should fail with return value SOCKET_ERROR.

    Any thoughts??

    • Dave Hillier
      Dave Hillier over 15 years
      It is slightly worrying that you're using UDP and asking that question. It probably means that you should be using TCP.
    • Guge
      Guge over 15 years
      I'd like to know if your non-existent host had an fictional IP-address in the same subnet as the origin of the datagram, or if it would have been on the outside of the router.