于是,下面一段代码就可以判断远端是否断开了连接:
-
try{
-
socket.sendUrgentData(
0xFF);
-
}
catch(Exception ex){
-
reconnect();
-
}
-
package com.csdn.test;
-
import java.io.BufferedReader;
-
import java.io.IOException;
-
import java.io.InputStreamReader;
-
public
class test {
-
static BufferedReader bufferedReader;
-
public static void main(String[] args) throws IOException {
-
try {
-
Process process = Runtime.getRuntime().exec(
"ping 192.168.1.104");
//判断是否连接的IP;
-
bufferedReader =
new BufferedReader(
new InputStreamReader(process
-
.getInputStream()));
-
String connectionStr =
"";
-
while ((connectionStr = bufferedReader.readLine()) !=
null) {
-
System.out.println(connectionStr);
-
}
-
}
catch (IOException e) {
-
e.printStackTrace();
-
}
finally {
-
bufferedReader.close();
-
}
-
}
-
}