开发者

Where did datagram packet go when their destination is offline?

Are those packet simply disappear? or they waits for the destination? Or the packet go back then throws an exception?

And in java, wh开发者_如何学编程at is the difference between the byte[] buffer with the length, in the DatagramPacket constructor?

DatagramPacket dp = new DatagramPacket(new byte[...], length);


From Wikipedia:

UDP is... Unreliable – When a message is sent, it cannot be known if it will reach its destination; it could get lost along the way. There is no concept of acknowledgment, retransmission or timeout.


Even if the destination is online, there is no guarantee, the UDP packet will arrive, arrive in the order sent, or not be fragmented. (I believe packets smaller than 532 bytes will not be fragmented) It is possible to have all three; fragmented, out of order and incomplete for the same packet.

The simplicity and stability of your network will determine how robust UDP packet delivery is, but you have to assume it is unreliable at least some of the time. All you can do is minimise the loss.

It is up to you to decide what to do if a packet is lost and how to detect it.

If you want broadcast, reliable delivery of messages I suggest you look at JMS Topics or Queues, like ActiveMQ.


If using UDP protocol, you can't guarantee that your packet is going to be received. So the answer is, it will be sent, even if its destination is not online.

TCP protocol, its guaranteed that costumer will receive the packet. Even if he is offline, once he get's online, that packet will be received.


Are those packet simply disappear? or they waits for the destination? Or the packet go back then throws an exception?

What happens depends on the nature of the "offline" status.

  • If the UDP message reaches the host, but the application is not listening, it will typically be silently discarded. It definitely won't be queued waiting for the application to listen. (That would be pointless, and potentially dangerous.)

  • If the UDP message cannot get to the host because the host itself is offline, the message will be silently discarded. (If the packets can reach the destination host's local network, then there is nothing apart from the host itself that can tell if the host actually received the packets.)

  • If the network doesn't know how to route the IP packets to the UDP server (and a few other scenarios), an ICMP "Destination Unreachable" packet may be sent to the sender, and that typically gets reported as a Java exception. However this is not guaranteed. So the possible outcomes are:

    • the UDP packet is black-holed and the sender gets no indication, or

    • the UDP packet is black-holed and the sender gets a Java exception.

  • If the UDP packet is blocked by a firewall, then the behaviour is hard to predict. (Firewalls often "lie" in their responses to unwanted traffic.)

The only situation where you would expect there to be queuing of UDP traffic is when the network is working, the host is working and the application is listening. Limited queuing is then possible if the application is slow in accepting the packets; i.e. it takes too long between successive calls to receive on the datagram socket. But even there, the queueing / buffering is strictly limited, and beyond that the messages will be dropped.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜