P
pselibas
Good day...
I have writen a method fo a program that checks to see if a port is
open on a specific host every 10 minutes to see if a particular service
is running.
public static boolean isPortUp(String host, int port){
boolean ret = true;
Socket MyClient = new Socket();
InetSocketAddress socketAddress = new InetSocketAddress(host,
port);
try {
MyClient.connect(socketAddress, 9000);
MyClient.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
ret = false;
}
return ret;
}
This method works perfectly well at first. Once the host goes down and
comes back up and this method i called again, an Exception is thrown
(Connection timeout). Does anyone know why this is and how i can fix
it.
Many Thanks.
I have writen a method fo a program that checks to see if a port is
open on a specific host every 10 minutes to see if a particular service
is running.
public static boolean isPortUp(String host, int port){
boolean ret = true;
Socket MyClient = new Socket();
InetSocketAddress socketAddress = new InetSocketAddress(host,
port);
try {
MyClient.connect(socketAddress, 9000);
MyClient.close();
}
catch (Exception e) {
System.out.println(e.getMessage());
ret = false;
}
return ret;
}
This method works perfectly well at first. Once the host goes down and
comes back up and this method i called again, an Exception is thrown
(Connection timeout). Does anyone know why this is and how i can fix
it.
Many Thanks.