18

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 do and what does it means when used in socket.bind()?

0

2 Answers 2

24

From the docs: The wildcard is a special local IP address. It usually means "any" and can only be used for bind operations.

The value of this IP address is 0.0.0.0. If you have two network adapters, one with IP address 1.1.1.1 and one with IP address 2.2.2.2, then you can create a listening socket and bind it to 1.1.1.1 so that the socket will not bind to 2.2.2.2. You can also create a listening socket and bind it to 2.2.2.2, so that it will not bind to 1.1.1.1. If you do not care and want your socket to bind to all network cards, then you bind it to the wildcard address.

Another special value would be 127.0.0.1, meaning that only clients on the same computer could connect to your server.

1
  • It can be used for connect() as well without bind
    – TheJoker
    Commented Apr 24, 2021 at 12:33
1

A wildcard mask is a mask of bits that indicates which parts of an IP address can assume any value. In the Cisco IOS, they are used in several places, for example:

  • To indicate the size of a network or subnet for some routing protocols, such as OSPF.
  • To indicate what IP addresses should be permitted or denied in access control lists (ACLs).

Not the answer you're looking for? Browse other questions tagged or ask your own question.