In the docs for the constructor InetSocketAddress(int port)
it says:
Creates a socket address where the IP address is the wildcard address and the port number a specified value.
What does a wildcard address does and what does it means when used in socket.bind()
?
From the docs:the wildcard is a special local IP address. It usually means "any" and can is only being used for bind operations.
The value of this IP address is 0.0.0.0. If you have both network adapters, one with the IP address 1.1.1.1 and one with the IP address 2.2.2.2, then you can create a Liste Ning socket and bind it to 1.1.1.1 so the socket would not bind to 2.2.2.2. You can also create a listening socket and bind it to 2.2.2.2, so it would not bind to 1.1.1.1. If you don't care and want your sockets to bind to all network cards, then you bind it to the wildcard address.
Another special value would be 127.0.0.1, meaning this only clients on the same computer could connect to your server.
What does wildcard address in inetsocketaddress mean?