I have a small project which needs internet connection. Unfortunately my internet is occasionally down. Then it throws away exception:
"java.net.SocketException: Network is unreachable"
...
My idea was to check internet connection before I do any operation and if it's down, just wait a few seconds and try again and again until its not working. But it throws same exception.
My code:
URL url = new URL("https://www.google.com");
URLConnection conn = url.openConnection();
InetAddress check = InetAddress.getByName("www.google.com");
while (check.isReachable(3000)) {
wait(5000);
}