• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Public IP Address (time limit)

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ! very appreciated
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic