socket.io-client-java
socket.io-client-java copied to clipboard
Stop reconnection
i am implementing chat app using this socket io. its working fine now i am getting one issue is that socket reconnecting again and again if socket connection off, i like this its handing own no need to handle manually. but in second scenario, when i switched off network or data connection of mobile then i used this code for socket off
public static void stopConnection() { try { if (mSocket != null) { mSocket.disconnect(); mSocket.close(); } } catch (Exception e) { e.printStackTrace(); } }
but its not working. socket making connection again and again and getting Error when network connection switched off. how can we handle this situation?
Hello guys, I'm working in a chat project to and I had the same problem. After read a lot of issue and comments my team and I, discover that is common problem.
In some comments we read people commenting about to use Socket.Io Manager class to definatly stop the socket, but no one explaing how to do that.
Few days ago,we finally found a way that really worked in our case.
Manager socketManager = mSocket.io(); socketManager.reconnection(false); mSocket.off(); mSocket.disconnect();
We discovered that because,if you define a IO.Options.reconnectionAttempts, after all attempts, the socket fall in EVENT_RECONNECT_FAILED and this event really stops the socket. Looking Socket.io search code, I found the famous Manager Class and I discovered that Manager Class stops the reconnecting loop setting the Manager.reconnecting var to false.
Just to be clear you don't need to set a "IO.Options.reconnectionAttempts" to work.
This solution worked for me, I hope works for you to guys.
See ya