delight-im / Android-DDP

[UNMAINTAINED] Meteor's Distributed Data Protocol (DDP) for clients on Android
Apache License 2.0
274 stars 54 forks source link

wifi -> lte, when internet connection is changed, Connection timed out is occured immediately #138

Open juceling opened 7 years ago

juceling commented 7 years ago

hi. thank you for your library. I have a question about reconnectivity. when I turned off LTE and connected with WIFI, reconnection is completed. but I turned off wifi and on LTE,

onException java.lang.Exception: com.neovisionaries.ws.client.WebSocketException: An I/O error occurred while a frame was being read from the web socket: Read error: ssl=0xae7acd80: I/O error during system call, Connection timed out

is occured immediately, 3 times. and do not try reconnect to server. so I inserted some code, "SystemClock.sleep(5000);", to wait establishing internet connection, and then turn off wifi and on lte. after that, reconnection is completed.

I want to reconnect to server automatically whenever internet connection is changed. but I think if internet is not available, library don`t wait and just stop and throw above error.

how can I do this... just check internet connection with ConnectivityManager, and control to wait to try reconnect by myself?

ocram commented 7 years ago

Thanks!

Could you perhaps provide more lines from the stack trace that you quoted? It would be interesting to know where this error was caused exactly.

When you turn off LTE (where the reconnection works), has WiFi been enabled as well before so that the device can immediately fall back to WiFi? Or do turn WiFi on manually after turning off LTE?

Analogously, when you turn off WiFi (where the reconnection does not work), has LTE been enabled as well before so that the device can immediately fall back to LTE? Or do turn LTE on manually after turning off WiFi?

Maybe we can catch that exception where it is caused in the library. Otherwise, we might try to implement a short waiting time around this line which grows with the number of reconnection attempts that have been made (mReconnectAttempts). What do you think? That should be roughly what you did with sleep.