| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | * |
| | | * @return The free port. |
| | | */ |
| | | public static SocketAddress findFreeSocketAddress() { |
| | | public static InetSocketAddress findFreeSocketAddress() { |
| | | try { |
| | | ServerSocket serverLdapSocket = new ServerSocket(); |
| | | serverLdapSocket.setReuseAddress(true); |
| | | serverLdapSocket.bind(new InetSocketAddress("127.0.0.1", 0)); |
| | | final SocketAddress address = serverLdapSocket.getLocalSocketAddress(); |
| | | serverLdapSocket.close(); |
| | | return address; |
| | | return (InetSocketAddress) address; |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | |
| | | * |
| | | * @return The socket address of the server. |
| | | */ |
| | | public static SocketAddress getServerSocketAddress() { |
| | | public static InetSocketAddress getServerSocketAddress() { |
| | | return LDAPServer.getInstance().getSocketAddress(); |
| | | } |
| | | |