How can I know that Android app reconnected to Socket.io? -


i have android application connects socket , emits connectiondata event on oncreate method.

// connect 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 , connection data socket     socket.connect();     socket.emit("connectiondata", currplayer.getplayerid()); } 

on server side, there activesockets hashmap stores <connectiondata, socket> data. when internet connection lost in app, server catches disconnect event , removes socket hashmap. , when app reconnects internet, connects socket well, app doesn't emit connectiondata anymore happens once activity created.

how can detect app reconnected socket on client side can emit connectiondata again?

add event listener:

socket.on(socket.event_connect, new emitter.listener() {     @override     public void call(final object... args) {         socket.emit("connectiondata", currplayer.getplayerid());     } }); 

see this q&a list of other events.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -