Here you can find the source of isHostReachable(String host, int port, int connTimeout)
Parameter | Description |
---|---|
host | a parameter |
port | a parameter |
connTimeout | a parameter |
public static boolean isHostReachable(String host, int port, int connTimeout)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; public class Main { /**// ww w.j av a 2 s . c om * Checks whether the given host and port is reachable or not. Tries to open a * socket with the given connection timeout. * @param host * @param port * @param connTimeout * @return */ public static boolean isHostReachable(String host, int port, int connTimeout) { Socket socket = null; boolean reachable = false; try { socket = new Socket(); socket.connect(new InetSocketAddress(host, port), connTimeout); reachable = true; } catch (IOException ioe) { } finally { if (socket != null) { try { socket.close(); } catch (IOException e) { } } } return reachable; } }