URL connection does not detect when online/offline
sanjiv sahayam
Greenhorn
Joined: Jan 25, 2002
Posts: 2
posted
0
Hi, I'm having a strange error with the URL class. I have written some code to poll a certain URL every second....thereby verifying if the Internet connection is functional. The code is shown below. If I have a working Internet connection and run the code, it says the connection is working. If I disable the internet connection is states the connection is not working. Re-enabling the connection again states that the connection is working, this is the expected behaviour. If I do the same as above but disconnect the Internet connection at the start, it never states that it connects even after the net connection is reestablished. I was wondering if the URL is cached somewhere such that after a number of unsuccessful attempts the JVM never tries again? Any help would be appreciated. Sanjiv public class connectiontest extends Thread { public connectiontest() {} public void run() { while(true) { try{ new URL("http://www.microsoft.com").openConnection().connect(); System.out.println("connected!!"); }catch(Exception e){System.out.println("could not connect");} try{ sleep(1000); } catch(InterruptedException ie){} } } public static void main(String args[]){ new connectiontest().start(); } }
subject: URL connection does not detect when online/offline