It is possible to determine the local address (and NetworkInterface) for a specific destination for DatagramChannels by connecting an unbound DatagramChannel to the destination and then checking the local address. It will be the local address of the NetworkInterface you want. This also works if the channel is explicitly bound to the wildcard address (but not any local address other than the one you are looking for). This works without generating any network traffic.
If you disconnect the channel then the local bound address becomes the wildcard again. The same behavior is seen across Windows, Linux and Macos.
This seems like very useful behavior that should be documented.
The same behavior exists in java.net.DatagramSocket and should be documented there also.
If you disconnect the channel then the local bound address becomes the wildcard again. The same behavior is seen across Windows, Linux and Macos.
This seems like very useful behavior that should be documented.
The same behavior exists in java.net.DatagramSocket and should be documented there also.
- csr for
-
JDK-8319962 (dc) DatagramChannel.connect undocumented behavior
-
- Closed
-