Monday 15 March 2010

networking - How to check if internet connection is present in java? -


How do you check whether you can connect to the internet from Java? There will be a way:

  final URL url = new URL ("http://www.google.com"); Final URL Connection = url.openConnection (); ... if we come here, we should be net ...  

But something more suitable for doing that task, especially if you do Is constant check and often the lack of internet connection is extremely possible?

You should be connected to the location that needs your actual application. Otherwise, you are checking whether you have any connection with irrelevant (Google in this case).

Specifically, if you are trying to talk to a web service, and if you are in control of the web service, it is a good idea to get some kind of cheaper "Get Status" Web Be the method. In this way there is a better idea about you that your "real" call is likely to work.

In other cases, just open a connection to a port which should be open enough - or a ping. There may also be an appropriate API for your needs.


No comments:

Post a Comment