One thing to note - there is no concept of "last" datagram with UDP. UDP doesn't guarantee that the sending order of datagrams is preserved on the receiving end so it may happen that the last datagram you receive is the first one of the whole series that was sent. Or that you don't receive the datagram at all. A common misconception in network programming is to treat the sender and receiver as one linked system (ignoring the nature of protocols connecting the systems) instead of treating them as autonomous systems exchanging data according to a set of rules (the protocol).