public static InetSocketAddress findFreeSocketAddress(){
  try (ServerSocket serverLdapSocket=new ServerSocket()){
    serverLdapSocket.setReuseAddress(true);
    serverLdapSocket.bind(new InetSocketAddress("127.0.0.1",0));
    return (InetSocketAddress)serverLdapSocket.getLocalSocketAddress();
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}

public static InetSocketAddress findFreeSocketAddress ( ) { try ( ServerSocket serverLdapSocket = new ServerSocket ( ) ) { serverLdapSocket . setReuseAddress ( true ) ; serverLdapSocket . bind ( new InetSocketAddress ( "127.0.0.1" , 0 ) ) ; return ( InetSocketAddress ) serverLdapSocket . getLocalSocketAddress ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } }
finds a free server socket port on the local host .
