Many hosts have more than one IP address. This is especially common at web server farms where a single machine is shared by multiple sites. By default, a server socket binds to all available IP addresses. That is it accepts connections addressed to any of the local IP addresses on a given port. However you can modify that behavior with this constructor:
public ServerSocket(int port, int backlog, InetAddress bindAddr)
throws IOException
You must also specify the queue length in this constructor.
try {
InetAddress ia = InetAddress.getByName("199.1.32.90");
ServerSocket ss = new ServerSocket(80, 50, ia);
}
catch (IOException ex) {
System.err.println(ex);
}
How would you bind to some but not all IP addresses on the server?