private static InetAddress findNonLoopbackAddress ( ) throws SocketException { final Enumeration < NetworkInterface > enumInterfaceAddress = NetworkInterface . getNetworkInterfaces ( ) ; while ( enumInterfaceAddress . hasMoreElements ( ) ) { final NetworkInterface netIf = enumInterfaceAddress . nextElement ( ) ; // Iterate over inet address final Enumeration < InetAddress > enumInetAdress = netIf . getInetAddresses ( ) ; while ( enumInetAdress . hasMoreElements ( ) ) { final InetAddress address = enumInetAdress . nextElement ( ) ; if ( ! address . isLoopbackAddress ( ) ) { return address ; } } } return null ; }
Find a non loopback address for this machine on which to start the server .