• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Public IP Address (time limit)

 
Juan Manuel Alberto de los Santos
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 624
IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ! very appreciated
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic