Choosing a local address
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 e) {
    System.err.println(e);
  }
How would you bind to some but not all IP addresses on the server?
Previous | Next | Top
Last Modified April 18, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu