2013-07-19 15:17:27 +02:00
|
|
|
package processing.app.helpers;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.InetAddress;
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.net.Socket;
|
|
|
|
|
|
|
|
public abstract class NetUtils {
|
|
|
|
|
2013-07-22 10:06:21 +02:00
|
|
|
public static boolean isReachable(InetAddress address, int port) {
|
2013-07-19 15:17:27 +02:00
|
|
|
Socket socket = null;
|
|
|
|
try {
|
|
|
|
socket = new Socket();
|
2015-02-16 20:11:17 +01:00
|
|
|
socket.connect(new InetSocketAddress(address, port), 300);
|
2013-07-19 15:17:27 +02:00
|
|
|
return true;
|
|
|
|
} catch (IOException e) {
|
|
|
|
return false;
|
|
|
|
} finally {
|
|
|
|
if (socket != null) {
|
|
|
|
try {
|
|
|
|
socket.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|