public static int findFreeLocalPort() throws IOException
    {
        try (ServerSocket serverSocket = new ServerSocket(0)){
            return serverSocket.getLocalPort();
        }
    }
Returns a local TCP port number that is likely to be available to use.

Note that during the execution of this method, the port is briefly in use. Also: there is no guarantee that after
this method returns, another process does not immediately start using the port that is returned.

@return A TCP port number
xmppserver/src/test/java/org/jivesoftware/openfire/session/LocalIncomingServerSessionTest.java