public static boolean isTcpPortAvailable ( int currentPort ) { try { Socket socket = SocketFactory . getDefault ( ) . createSocket ( InetAddress . getLocalHost ( ) , currentPort ) ; socket . close ( ) ; return false ; } catch ( Throwable e ) { return true ; } }
Check whether the given TCP port is available .