| Author |
Public IP Address (time limit)
|
Juan Manuel Alberto de los Santos
Ranch Hand
Joined: Jun 26, 2008
Posts: 48
|
|
I use this code to get the public IP address, it works perfectly, but sometimes takes too long and blocks everything, is there any way to put a time limit ? for example, if in 5 seconds the program doesn't retrive the IP address, stop and print "couldn't find ip, try later" thanks ! [ August 04, 2008: Message edited by: Juan Manuel Alberto de los Santos ]
|
 |
Mark Vedder
Ranch Hand
Joined: Dec 17, 2003
Posts: 624
|
|
If you look at the JavaDoc for the getInputStream() method you are using (which actually exists in the URLConnection super class), you will see a "See Also" notation that points to the setReadTimeout(int) and getReadTimeout() methods. These can be used to set read timeouts. The HttpURLConnection class also has a setConnectTimeout(int) method, which is also inherited from the URLConnection superclass. More info is available in the Javadoc for the method (see link). [ August 04, 2008: Message edited by: Mark Vedder ]
|
 |
Juan Manuel Alberto de los Santos
Ranch Hand
Joined: Jun 26, 2008
Posts: 48
|
|
Thanks ! very appreciated
|
 |
 |
|
|
subject: Public IP Address (time limit)
|
|
|