Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does wildcard address in InetSocketAddress mean?

Tags:

java

sockets

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()?

like image 725
goh Avatar asked Aug 13 '12 09:08

goh


People also ask

How do you use a wildcard in an IP address?

In a policy, you only have to specify the wildcard IP address rather than add each individual IP address. To configure wildcard IP addresses in an alias or policy, you specify wildcard values in one or more octets in the netmask. Netmask values can be any number from 0 to 255.

Why do we use wildcard?

Wildcards are special characters that can stand in for unknown characters in a text value and are handy for locating multiple items with similar, but not identical data. Wildcards can also help with getting data based on a specified pattern match. For example, finding everyone named John on Park Street.

What is unresolved socket address?

It's an intermediary step.. And From API: It can also be a pair (hostname + port number), in which case an attempt will be made to resolve the hostname. If resolution fails then the address is said to be unresolved but can still be used on some circumstances like connecting through a proxy.

What is socket address?

A socket address is defined by the IP address of the socket and the port number allocated to the socket.

What does a socket wildcard address do?

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 ()? From the docs: The wildcard is a special local IP address. It usually means "any" and can only be used for bind operations.

What is the value of inetsocketaddress?

InetSocketAddress (int port) : Creates a socketaddress object with the specified port number and a wildcard IP address. A wildcard IP address has the value 0.0.0.0 and it binds your socket to all network cards.

What is a wildcard IP address?

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.

What is inetsocketaddress class in Java?

The objects of this class are immutable and can be used for binding, connecting purposes. 1. InetSocketAddress (InetAddress addr, int port) : This constructor is similar to the general structure of a socket address with the attributes for Inet address and port number.


2 Answers

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.

like image 131
Werner Henze Avatar answered Sep 21 '22 05:09

Werner Henze


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).
like image 33
user2268854 Avatar answered Sep 22 '22 05:09

user2268854