Hi Mark,

On 30/09/2019 12:56, mark sheppard wrote:
the first uses the InetSocketAddress allocated and then the second uses the 
same address, without bind  exception because of
the SO_REUSEADDR option being set,  even if the close had not completed at that 
time.

No. The second doesn't use the address. I agree that it might - if
e.g. the system has run out of ephemeral ports, but I believe  it's
highly unlikely.

$ jshell
jshell>  InetSocketAddress clientAddress =
...> new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
clientAddress ==> localhost/127.0.0.1:0

jshell> try (MulticastSocket s = new MulticastSocket(clientAddress)) {
   ...>             // no-op; close immediately
   ...>             System.out.println(s.getLocalPort());
   ...> }
59951

jshell> MulticastSocket s = new MulticastSocket(clientAddress);
s ==> java.net.MulticastSocket@1a86f2f1

jshell> System.out.println(s.getLocalPort());
55379

best regards,

-- daniel

Reply via email to