protected boolean isAvailable(final NetworkPort port) {

        int portNumber = port.getPortNumber();

        try {
            try (ServerSocket tcp = new ServerSocket(portNumber);
                 DatagramSocket udp = new DatagramSocket(portNumber)) {
                return tcp.isBound() && udp.isBound();
            }
        } catch (IOException e) { //NOSONAR
            LOG.debug("Port {} not available", port.getSocketAddress(), e);
            return false;
        }
    }
protected boolean isAvailable ( final NetworkPort port ) { int portNumber = port . getPortNumber ( ) ; try { try ( ServerSocket tcp = new ServerSocket ( portNumber ) ; DatagramSocket udp = new DatagramSocket ( portNumber ) ) { return tcp . isBound ( ) && udp . isBound ( ) ; } } catch ( IOException e ) { LOG . debug ( "Port {} not available" , port . getSocketAddress ( ) , e ) ; return false ; } }
Checks the availability of a tcpPort by checking if a {@link ServerSocket} is already bound.

@param port
the port to check

@return <code>true</code> if the port is available