I'm new to socket programming, with lots of questions in mind.
I wrote a code to check internet availability. When running via netbeans IDE launch, It detects availability of internet connection...
Sentence in blue means internet connection available.
When running built jar, It throws a timeout error and doesn't check availability...
and the second step's image is :
Sentence in red means no internet access.
Here's code. Any idea on what's the problem? I'm confused because it's not a regular issue.
private void checkInternetConnection()
{
Socket socket = null;
try
{
socket = new Socket("varzesh3.com", 80);
socket.setSoTimeout(50000);
lblStatus.setForeground(Color.blue);
lblStatus.setText("اینترنت فعال است");
socket.close();
timer.stop();
}
catch (IOException ex)
{
lblStatus.setForeground(Color.red);
lblStatus.setText("اینترنت غیر فعال است");
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
Thanks for your attention.