How can I check socket.io connect or disconnect on android?

I connect to the node server with socketio.SocketIO running as a service.And, When Service restarts,opens socket.io without socket.io closure.That's a problem.

A device making multiple socketIO connection on the server side.So the server is swelling..


! I am using gottox/socketio-java-client on android.

Check Socket is connected or not using socket.isConnected(). This will return true if socket is connected

You can check the socket.connected property:

var socket = io.connect();
console.log('check 1', socket.socket.connected);
socket.on('connect', function() {
  console.log('check 2', socket.socket.connected);
});
It's updated dynamically, if the connection is lost it'll be set to false until the client picks up the connection again. So easy to check for with setInterval or something like that.

Another solution would be to catch disconnect events and track the status yourself.