Determine if internet connection is available using Java in NetBeans
Download the code :
https://drive.google.com/folderview?id=0B4fPeBZJ1d19ck52TUpNenBtLVU&usp=sharing
package application;
import java.net.*;
public class InternetConnection
{
public static boolean InternetConnection ()
{
Socket sock = new Socket();
InetSocketAddress addr = new InetSocketAddress("www.google.com",80);
try
{
sock.connect(addr,3000);
//JOptionPane.showMessageDialog(null,"You are connected!");
return true;
}
catch (Exception e)
{
//JOptionPane.showMessageDialog(null,"Please check your Internet Connection!");
return false;
}
finally
{
try
{
sock.close();
}
catch (Exception e)
{
}
}
}
}
►Facebook : https://www.facebook.com/TechWorld3g ►Twitter : https://twitter.com/TechWorld3g ►Youtube : https://www.youtube.com/user/TechWorld3g ►Blog : https://tech-world3g.blogspot.com ►Donate : https://imraising.tv/u/techworld3g
No comments:
Post a Comment