forked from KNEMC/KLALB
增加延迟检测功能
This commit is contained in:
@@ -6,6 +6,7 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public class TCPConnection {
|
||||
@@ -64,6 +65,13 @@ public class TCPConnection {
|
||||
|
||||
public void setDelay(long delay) {
|
||||
this.delay = delay;
|
||||
if(connect!=null) {
|
||||
try {
|
||||
connect.setSoTimeout((int) (delay/500000));
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TCPConnection(Tunnel t) throws UnknownHostException, IOException {
|
||||
@@ -84,4 +92,16 @@ public class TCPConnection {
|
||||
return !connect.isClosed();
|
||||
}
|
||||
|
||||
|
||||
private volatile long time=System.nanoTime();
|
||||
public boolean checkPingTime() {
|
||||
long cu=System.nanoTime();
|
||||
if(cu-time>Consts.PINGTIMENS) {
|
||||
time=cu;
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user