我试图检查服务器是否可用,但运行此代码时,我得到错误的服务器不可用或有时申请冻结,即使服务器运行正常:检查服务器可用性不工作
InetAddress in;
in = null;
try {
in = InetAddress.getByAddress(new byte[] { (byte)192, (byte)168, (byte)16, (byte)48});
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
if (in.isReachable(5000)) {
loadProduct();
} else
{
showAlertBox("Warning", "Server not available!");
}
} catch (IOException e) {
showAlertBox("Warning", "Server not available!");
}
有没有更好的方法来检查服务器是否在线?
我找到简单的解决方案在http://stackoverflow.com/a/15785326/1866833 感谢所有。 – Josef