//check whether internet is available or not.
public boolean isReachable(String address, int port, int timeoutMs) {
try {
Socket sock = new Socket();
SocketAddress sockaddr = new InetSocketAddress(address, port);
sock.connect(sockaddr, timeoutMs); // this will block no more than timeoutMs
sock.close();
return true;
} catch (IOException e) { return false; }
}
No comments:
Post a Comment