• Post Reply Bookmark Topic Watch Topic
  • New Topic

URL connection does not detect when online/offline  RSS feed

 
sanjiv sahayam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
}
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!