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("");
    ServerSocket ss = new ServerSocket(80, 50, ia);
  catch (IOException ex) {
How would you bind to some but not all IP addresses on the server?

Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
Last Modified April 18, 1997