public static boolean isSocketAlive ( final SocketAddress socketAddress , final int timeoutMsecs ) { final Socket socket = new Socket ( ) ; try { socket . connect ( socketAddress , timeoutMsecs ) ; socket . close ( ) ; return true ; } catch ( final SocketTimeoutException exception ) { return false ; } catch ( final IOException exception ) { return false ; } }
Returns true if a connection can be established to the given socket address within the timeout provided .