Tried adding smt to avoid being kicked off the Server
This commit is contained in:
parent
96b0fa70ef
commit
67cd93403a
@ -35,28 +35,33 @@ public class ClientPinger implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
Thread.currentThread().setPriority(10);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(20000);
|
Thread.sleep(20000);
|
||||||
while (socket.isConnected() && !socket.isClosed()) {
|
} catch (InterruptedException e) {
|
||||||
gotPingBack = false;
|
Thread.currentThread().interrupt();
|
||||||
client.sendMsgToServer(Protocol.pingFromClient);
|
}
|
||||||
|
while (socket.isConnected() && !socket.isClosed()) {
|
||||||
|
gotPingBack = false;
|
||||||
|
client.sendMsgToServer(Protocol.pingFromClient);
|
||||||
|
try {
|
||||||
Thread.sleep(4000);
|
Thread.sleep(4000);
|
||||||
if (gotPingBack) {
|
} catch (InterruptedException e) {
|
||||||
if (!isConnected) { //if !isConnected, then the connection had been lost before.
|
Thread.currentThread().interrupt();
|
||||||
isConnected = true;
|
}
|
||||||
System.out.println("Connection regained!");
|
if (gotPingBack) {
|
||||||
}
|
if (!isConnected) { //if !isConnected, then the connection had been lost before.
|
||||||
} else {
|
isConnected = true;
|
||||||
if (isConnected) {
|
System.out.println("Connection regained!");
|
||||||
isConnected = false;
|
}
|
||||||
System.out.println("Lost connection. Waiting to reconnect...");
|
} else {
|
||||||
}
|
if (isConnected) {
|
||||||
|
isConnected = false;
|
||||||
|
System.out.println("Lost connection. Waiting to reconnect...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isConnected = false;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
isConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGotPingBack(boolean gotPingBack) {
|
public void setGotPingBack(boolean gotPingBack) {
|
||||||
|
|||||||
@ -37,6 +37,7 @@ public class ServerPinger implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
Thread.currentThread().setPriority(10);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
while (socket.isConnected() && !socket.isClosed()) {
|
while (socket.isConnected() && !socket.isClosed()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user