I have an android application that connects to a socket and emits connectionData
event on the onCreate
method.
// connect to socket
private Socket socket;
{
try {
socket = IO.socket(AppConfig.URL_SOCKET_IO);
} catch (URISyntaxException e) {
Log.e(LOG_TAG, "error");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// emit connect and connection data socket
socket.connect();
socket.emit("connectionData", currPlayer.getPlayerID());
}
On the server side, there is activeSockets
HashMap which stores <connectionData, socket>
data. When the internet connection is lost in the app, the server catches disconnect
event and removes the socket from the HashMap. And when the app reconnects to the internet, it connects to the socket as well, but the app doesn't emit connectionData
anymore as it only happens once the activity is created.
How can I detect that the app reconnected to the socket on the client-side so that I can emit connectionData
again?