Skip to content

Commit 5857a71

Browse files
committed
fix ping schedule issue
1 parent 7115c3e commit 5857a71

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
<parent>
77
<groupId>com.tvd12</groupId>
88
<artifactId>ezyfox</artifactId>
9-
<version>1.0.0</version>
9+
<version>1.0.1</version>
1010
</parent>
1111

1212
<artifactId>ezyfox-server-java-client</artifactId>
1313

14-
<version>1.1.5</version>
14+
<version>1.1.6</version>
1515
<name>ezyfox-server-java-client</name>
1616
<url>https://youngmonkeys.org/</url>
1717

1818
<properties>
19-
<ezy.version>1.1.9</ezy.version>
19+
<ezy.version>1.2.0</ezy.version>
2020
</properties>
2121

2222
<dependencies>

src/main/java/com/tvd12/ezyfoxserver/client/EzyClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import com.tvd12.ezyfoxserver.client.manager.EzyPingManager;
1414
import com.tvd12.ezyfoxserver.client.request.EzyRequest;
1515
import com.tvd12.ezyfoxserver.client.setup.EzySetup;
16-
import com.tvd12.ezyfoxserver.client.socket.EzyISocketClient;
1716
import com.tvd12.ezyfoxserver.client.socket.EzyPingSchedule;
17+
import com.tvd12.ezyfoxserver.client.socket.EzySocketClient;
1818

1919
/**
2020
* Created by tavandung12 on 9/20/18.
@@ -90,7 +90,7 @@ public interface EzyClient extends EzyCloseable {
9090

9191
byte[] getPublicKey();
9292

93-
EzyISocketClient getSocket();
93+
EzySocketClient getSocket();
9494

9595
EzyApp getApp();
9696

src/main/java/com/tvd12/ezyfoxserver/client/EzyTcpClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.tvd12.ezyfoxserver.client.request.EzySimpleRequestSerializer;
3232
import com.tvd12.ezyfoxserver.client.setup.EzySetup;
3333
import com.tvd12.ezyfoxserver.client.setup.EzySimpleSetup;
34-
import com.tvd12.ezyfoxserver.client.socket.EzyISocketClient;
3534
import com.tvd12.ezyfoxserver.client.socket.EzyPingSchedule;
3635
import com.tvd12.ezyfoxserver.client.socket.EzySocketClient;
3736
import com.tvd12.ezyfoxserver.client.socket.EzyTcpSocketClient;
@@ -304,7 +303,7 @@ public byte[] getPrivateKey() {
304303
}
305304

306305
@Override
307-
public EzyISocketClient getSocket() {
306+
public EzySocketClient getSocket() {
308307
return socketClient;
309308
}
310309

src/main/java/com/tvd12/ezyfoxserver/client/socket/EzyPingSchedule.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import com.tvd12.ezyfox.util.EzyLoggable;
99
import com.tvd12.ezyfoxserver.client.EzyClient;
1010
import com.tvd12.ezyfoxserver.client.constant.EzyDisconnectReason;
11-
import com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent;
12-
import com.tvd12.ezyfoxserver.client.event.EzyEvent;
1311
import com.tvd12.ezyfoxserver.client.event.EzyLostPingEvent;
1412
import com.tvd12.ezyfoxserver.client.manager.EzyPingManager;
1513
import com.tvd12.ezyfoxserver.client.request.EzyPingRequest;
@@ -79,8 +77,7 @@ private void sendPingRequest() {
7977
int lostPingCount = pingManager.increaseLostPingCount();
8078
int maxLostPingCount = pingManager.getMaxLostPingCount();
8179
if(lostPingCount >= maxLostPingCount) {
82-
EzyEvent event = new EzyDisconnectionEvent(EzyDisconnectReason.SERVER_NOT_RESPONDING.getId());
83-
socketEventQueue.addEvent(event);
80+
client.getSocket().disconnect(EzyDisconnectReason.SERVER_NOT_RESPONDING.getId());
8481
}
8582
else {
8683
client.send(EzyPingRequest.getInstance());

src/main/java/com/tvd12/ezyfoxserver/client/socket/EzySocketClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,11 @@ else if (socketWriter.isStopped()) {
310310
}
311311

312312
protected void processReceivedMessages0() {
313-
pingManager.setLostPingCount(0);
314313
popReadMessages();
315314
try {
315+
if (localMessageQueue.size() > 0) {
316+
pingManager.setLostPingCount(0);
317+
}
316318
for (int i = 0; i < localMessageQueue.size(); ++i) {
317319
processReceivedMessage(localMessageQueue.get(i));
318320
}

src/test/java/com/tvd12/ezyfoxserver/client/testing/EzyHelloClientTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
import com.tvd12.ezyfoxserver.client.config.EzyClientConfig;
1515
import com.tvd12.ezyfoxserver.client.constant.EzyCommand;
1616
import com.tvd12.ezyfoxserver.client.entity.EzyApp;
17+
import com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent;
1718
import com.tvd12.ezyfoxserver.client.event.EzyEventType;
1819
import com.tvd12.ezyfoxserver.client.handler.EzyAppAccessHandler;
1920
import com.tvd12.ezyfoxserver.client.handler.EzyAppDataHandler;
2021
import com.tvd12.ezyfoxserver.client.handler.EzyConnectionFailureHandler;
2122
import com.tvd12.ezyfoxserver.client.handler.EzyConnectionSuccessHandler;
23+
import com.tvd12.ezyfoxserver.client.handler.EzyDisconnectionHandler;
2224
import com.tvd12.ezyfoxserver.client.handler.EzyHandshakeHandler;
2325
import com.tvd12.ezyfoxserver.client.handler.EzyLoginSuccessHandler;
2426
import com.tvd12.ezyfoxserver.client.handler.EzyUdpHandshakeHandler;
@@ -33,41 +35,52 @@ public class EzyHelloClientTest {
3335

3436
public static void main(String[] args) throws Exception {
3537
EzyClientConfig clientConfig = EzyClientConfig.builder()
36-
.clientName("first")
38+
.clientName("example")
3739
.zoneName("example")
40+
.pingConfigBuilder()
41+
.pingPeriod(1000)
42+
.done()
3843
.build();
3944
EzyClients clients = EzyClients.getInstance();
4045
EzyClient client = new EzyUTClient(clientConfig);
4146
clients.addClient(client);
4247
EzySetup setup = client.setup();
4348
setup.addEventHandler(EzyEventType.CONNECTION_SUCCESS, new EzyConnectionSuccessHandler());
4449
setup.addEventHandler(EzyEventType.CONNECTION_FAILURE, new EzyConnectionFailureHandler());
50+
setup.addEventHandler(EzyEventType.DISCONNECTION, new EzyDisconnectionHandler());
4551
setup.addDataHandler(EzyCommand.HANDSHAKE, new HelloHandshakeEventHandler());
4652
setup.addDataHandler(EzyCommand.LOGIN, new HelloLoginSuccessHandler());
4753
setup.addDataHandler(EzyCommand.APP_ACCESS, new HelloAccessAppHandler());
4854
setup.addDataHandler(EzyCommand.UDP_HANDSHAKE, new HelloUdpHandshakeHandler());
4955

50-
EzyAppSetup appSetup = setup.setupApp("hello");
56+
EzyAppSetup appSetup = setup.setupApp("hello-world");
5157
appSetup.addDataHandler("hello", new HelloMessageResponseHandler());
5258

53-
client.connect("127.0.0.1", 3005);
59+
client.connect("tvd12.com", 3005);
5460

5561
EzyMainEventsLoop mainEventsLoop = new EzyMainEventsLoop();
5662
mainEventsLoop.start();
5763
}
5864
}
5965

66+
class DisconnectionHandler extends EzyDisconnectionHandler {
67+
@Override
68+
protected void postHandle(EzyDisconnectionEvent event) {
69+
System.out.print("disconnected");
70+
}
71+
}
72+
6073
class HelloHandshakeEventHandler extends EzyHandshakeHandler {
6174
@Override
6275
protected EzyRequest getLoginRequest() {
63-
return new EzyLoginRequest("hello", "dungtv", "123456");
76+
return new EzyLoginRequest("example", "dungtv", "123456");
6477
}
6578
}
6679

6780
class HelloLoginSuccessHandler extends EzyLoginSuccessHandler {
6881
@Override
6982
protected void handleLoginSuccess(EzyData responseData) {
70-
client.send(new EzyAppAccessRequest("hello"));
83+
client.send(new EzyAppAccessRequest("hello-world"));
7184
}
7285
}
7386

0 commit comments

Comments
 (0)