判断 socket 状态

This commit is contained in:
chengdu
2019-07-13 18:10:57 +08:00
parent 4b8b8397d1
commit 6311c74414
3 changed files with 75 additions and 14 deletions

View File

@@ -1748,6 +1748,14 @@ public class StorageClient {
this.storageServer.getSocket().getOutputStream().write(wholePkg);
}
public boolean isConnected(){
return trackerServer.isConnected();
}
public boolean isAvaliable(){
return trackerServer.isAvaliable();
}
/**
* Upload file by file buff
*

View File

@@ -78,4 +78,36 @@ public class TrackerServer {
protected void finalize() throws Throwable {
this.close();
}
public boolean isConnected(){
boolean isConnected = false;
if (sock != null){
if (sock.isConnected()){
isConnected = true;
}
}
return isConnected;
}
public boolean isAvaliable(){
if(isConnected()){
if(sock.getPort() == 0){
return false;
}
if(sock.getInetAddress() == null){
return false;
}
if(sock.getRemoteSocketAddress() == null){
return false;
}
if(sock.isInputShutdown()){
return false;
}
if(sock.isOutputShutdown()){
return false;
}
return true;
}
return false;
}
}