Using 0.0.0.0
will only bind to IPv4-enabled interfaces. However, if you bind to ::
, that should cover all IPv4 and IPv6 interfaces, assuming your TCP/IP stack (and Java) have IPv4-compatible IPv6 sockets enabled.
You’ll need to look to the kernel (or socket libraries, if you’re on Windows) for an explanation of “why”. On my OS X system, the man
pages explain it.
From man 4 inet`:
Sockets may be created with the local address
INADDR_ANY
to effect
‘wildcard’ matching on incoming messages. The address in a connect(2)
or sendto(2) call may be given asINADDR_ANY
to mean ‘this host’. The
distinguished addressINADDR_BROADCAST
is allowed as a shorthand for the
broadcast address on the primary network if the first network configured
supports broadcast.
From man 4 inet6:
Sockets may be created with the local address
::
(which is equal to
IPv6 address0:0:0:0:0:0:0:0
) to affect ‘wildcard’ matching on incoming
messages.