增加延迟检测功能

This commit is contained in:
Administrator
2022-11-27 10:19:45 +08:00
parent 4f2b416ac3
commit 913313b2a8
4 changed files with 64 additions and 14 deletions
@@ -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;
}
}
}