It's not a secret anymore!*
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
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)
 
Similar Threads
Can a client lie about its IP address to the server using Java?
Writing java wrapper class
how getting console output into a JTextArea
Read from BufferedInputStream
Problem with Hebrew encoding