When an active (bound or connected) DatagramSocket object goes out of scope, it can take several seconds for the local UDP port being used by it to be freed/reclaimed by the lower networking layers. During that time, other UDP sockets on the machine will not be able to use the port.

It is strongly recommended that DatagramSocket instances be explicitly closed before they go out of scope (e.g., before application exit).