The moose likes Sockets and Internet Protocols and the fly likes URL connection does not detect when online/offline Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "URL connection does not detect when online/offline " Watch "URL connection does not detect when online/offline " New topic
Author

URL connection does not detect when online/offline

sanjiv sahayam
Greenhorn

Joined: Jan 25, 2002
Posts: 2
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
 
Threads others viewed
URL connection does not detect when online/offline
not able to connect...
multithread problem - start is not calling run() - child thread is not completing before parent
Holy SPANK!! I got a connection...
New to CORBA, problem with java client application
IntelliJ Java IDE