deepstream.io-client-java
deepstream.io-client-java copied to clipboard
Frequent disconnect with Deepstream server from java client
Hello @yasserf
As i have been using and testing deepstream 2.0.0 rc1 release and its working fine with node client. But with java client when i use it in android it gets frequent disconnects on its own.
Also i have below logs which shows behaviour of dis-connectivity.
12-02 14:22:47.787 com.test : GCM2 connectStateChange : AUTHENTICATING , AUTHENTICATING
12-02 14:22:47.798 com.test : GCM2 connectStateChange : AWAITING_CONNECTION , AWAITING_CONNECTION
12-02 14:22:47.802 com.test : GCM2 connectStateChange : CHALLENGING , CHALLENGING
12-02 14:22:48.564 com.test : GCM2 connectStateChange : AWAITING_AUTHENTICATION , AWAITING_AUTHENTICATION
12-02 14:22:48.568 com.test : GCM2 connectStateChange : AUTHENTICATING , AUTHENTICATING
12-02 14:22:49.149 com.test : GCM2 connectStateChange : OPEN , OPEN
12-02 14:22:49.151 com.test : GCM2 login success :
12-02 14:23:02.602 com.test : GCM2 message : tryReconnect
12-02 14:23:02.645 com.test : GCM2 message : tryReconnect time : 1000 , 1
12-02 14:23:02.646 com.test : GCM2 connectStateChange : RECONNECTING , RECONNECTING
12-02 14:23:05.531 com.test : GCM2 connectStateChange : AUTHENTICATING , AUTHENTICATING
12-02 14:23:05.556 com.test : GCM2 connectStateChange : AWAITING_CONNECTION , AWAITING_CONNECTION
12-02 14:23:05.558 com.test : GCM2 connectStateChange : CHALLENGING , CHALLENGING
12-02 14:23:07.035 com.test : GCM2 connectStateChange : AWAITING_AUTHENTICATION , AWAITING_AUTHENTICATION
12-02 14:23:07.036 com.test : GCM2 connectStateChange : AUTHENTICATING , AUTHENTICATING
12-02 14:23:07.898 com.test : GCM2 connectStateChange : OPEN , OPEN
12-02 14:23:08.813 com.test : GCM2 exception : EAS584002b971722b1820d4b5bf/commands , event : UNSOLICITED_MESSAGE
12-05 10:23:19.815 com.test : GCM2 message : tryReconnect
12-05 10:23:19.816 com.test : GCM2 message : tryReconnect time : 2000 , 2
12-05 10:23:19.816 com.test : GCM2 connectStateChange : RECONNECTING , RECONNECTING
12-05 10:23:23.591 com.test : GCM2 connectStateChange : AUTHENTICATING , AUTHENTICATING
12-05 10:23:23.603 com.test : GCM2 connectStateChange : AWAITING_CONNECTION , AWAITING_CONNECTION
12-05 10:23:23.605 com.test : GCM2 connectStateChange : CHALLENGING , CHALLENGING
12-05 10:23:24.929 com.test : GCM2 connectStateChange : AWAITING_AUTHENTICATION , AWAITING_AUTHENTICATION
12-05 10:23:24.930 com.test : GCM2 connectStateChange : AUTHENTICATING , AUTHENTICATING
12-05 10:23:25.596 com.test : GCM2 connectStateChange : OPEN , OPEN
12-05 10:23:26.320 com.test : GCM2 exception : EAS584002b971722b1820d4b5bf/commands , event : UNSOLICITED_MESSAGE
12-05 10:23:53.710 com.test : GCM2 message : onClose : false , false , p.appice.io:6020/deepstream , p.appice.io:6020/deepstream
12-05 10:23:53.720 com.test : GCM2 message : tryReconnect
12-05 10:23:53.727 com.test : GCM2 message : onClose : false , false , p.appice.io:6020/deepstream , p.appice.io:6020/deepstream
12-05 10:23:53.729 com.test : GCM2 message : tryReconnect
12-05 10:23:53.730 com.test : GCM2 message : tryReconnect time : 4000 , 3
12-05 10:23:53.731 com.test : GCM2 connectStateChange : RECONNECTING , RECONNECTING
12-05 10:23:58.890 com.test : GCM2 connectStateChange : AUTHENTICATING , AUTHENTICATING
12-05 10:23:58.902 com.test : GCM2 connectStateChange : AWAITING_CONNECTION , AWAITING_CONNECTION
12-05 10:23:58.905 com.test : GCM2 connectStateChange : CHALLENGING , CHALLENGING
12-05 10:24:00.119 com.test : GCM2 connectStateChange : AWAITING_AUTHENTICATION , AWAITING_AUTHENTICATION
12-05 10:24:00.124 com.test : GCM2 connectStateChange : AUTHENTICATING , AUTHENTICATING
12-05 10:24:00.733 com.test : GCM2 connectStateChange : OPEN , OPEN
12-05 10:24:01.051 com.test : GCM2 exception : EAS584002b971722b1820d4b5bf/commands , event : UNSOLICITED_MESSAGE
12-05 10:24:53.884 com.test : GCM2 message : onClose : false , false , p.appice.io:6020/deepstream , p.appice.io:6020/deepstream
12-05 10:24:53.886 com.test : GCM2 message : tryReconnect
Also their is just retry of max 5 times. So i have update code in Connection.java class under below function to just reconnects again to server if its not connected currently. And added a broadcast receiver to intercept internet re-connectivity to reconnect to server back again.
public void tryReconnect() {
this.client.onMessage("tryReconnect");
if (this.reconnectTimeout != null) {
return;
}
// int maxReconnectAttempts = options.getMaxReconnectAttempts();
// int reconnectIntervalIncrement = options.getReconnectIntervalIncrement();
// int maxReconnectInterval = options.getMaxReconnectInterval();
// if (this.reconnectionAttempt < maxReconnectAttempts) {
// this.setState(ConnectionState.RECONNECTING);
// this.reconnectTimeout = new Timer();
// this.reconnectTimeout.schedule(new TimerTask() {
// public void run() {
// tryOpen();
// }
// }, Math.min(
// reconnectIntervalIncrement * this.reconnectionAttempt,
// maxReconnectInterval
// ));
// this.reconnectionAttempt++;
//
// } else {
// this.clearReconnect();
// this.close();
// }
//
long tryTime = 0;
if (this.reconnectionAttempt == 0 || this.reconnectionAttempt >= 7) {
tryTime = 1000;
this.reconnectionAttempt = 1;
} else {
tryTime = ((int) Math.pow(2, this.reconnectionAttempt)) * 1000;
this.reconnectionAttempt++;
}
this.client.onMessage("tryReconnect time : " + tryTime + " , " + this.reconnectionAttempt);
this.setState(ConnectionState.RECONNECTING);
this.reconnectTimeout = new Timer();
this.reconnectTimeout.schedule(new TimerTask() {
public void run() {
tryOpen();
}
}, tryTime);
}