File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Public IP Address (time limit) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Public IP Address (time limit)" Watch "Public IP Address (time limit)" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Public IP Address (time limit)