判断 socket 状态
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user