①IPアドレスだけチェックするメソッド:
仅仅验证IP地址的方法:
String host = "192.168.1.181"
int timeOut = 3000 ; //超???在3?以上
boolean status = InetAddress.getByName(host).isReachable(timeOut);
int timeOut = 3000 ; //超???在3?以上
boolean status = InetAddress.getByName(host).isReachable(timeOut);
②あるサービスのチェックメソッド:
验证某个服务器的方法(应用多)
// サーバ接続先を使用し、Webサービスに接続する
String mtrcsServerURL =
http://10.10.4.12:8080/xxxxxxx;
URL url = new URL(mtrcsServerURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.getResponseCode();
URL url = new URL(mtrcsServerURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.getResponseCode();
接続失敗の場合、異常SocketExceptionがスローされました。
接续失败的情况下,SocketException异常会被抛出。