5
votes

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??

6
It is slightly worrying that you're using UDP and asking that question. It probably means that you should be using TCP.Dave Hillier
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.Guge

6 Answers

6
votes

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

5
votes

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.

3
votes

"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."

3
votes

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

2
votes

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.

1
votes

If you need reliable UDP as in ordering or verification such that TCP/IP will give you take a look at RUDP or Reliable UDP. Sometimes you do need verification but a mixture of UDP and TCP can be held up on the TCP reliability causing a bottleneck.

For most large scale MMO's for isntance UDP and Reliablity UDP are the means of communication and reliability. All RUDP does is add a smaller portion of TCP/IP to validate and order certain messages but not all.

A common game development networking library is Raknet which has this built in.

RUDP http://www.javvin.com/protocolRUDP.html

An example of RUDP using Raknet and Python http://pyraknet.slowchop.com/