I have a multi-homed machine, and I'd like to have my ServerSocket listening only to a particular one of the IP addresses. How can I do this?

Tim Rohaly

ServerSocket always listens on only one of the IP addresses, but the default constructor doesn't let you choose which IP to use on a multi-homed machine.

There is another constructor, public ServerSocket(int port, int backlog, InetAddress bindAddr), that lets you specify the IP address to bind to when on a multi-homed machine. Simply specify the InetAddress you wish to listen on as the third argument.