socket.io-client-dart icon indicating copy to clipboard operation
socket.io-client-dart copied to clipboard

Android: Makes multiple calls for connection

Open connectprabhjeet opened this issue 2 years ago • 4 comments

I'm using this with Socketio on the node server. For the first time when the app launches, only 1 call is made to establish a connection which is expected. But if you minimize the app and lock your phone (I was testing it on the emulator), after the socket disconnects, reopen the application and let it auto connect. Now here it makes multiple calls for connection. If the above steps make say 2 connection requests, then at the time of disconnect the server shows the reason of disconnect as transport close and ping timeout for these connection requests. I have even seen 10-12 connection requests by minimizing and reopening several times followed by the above-mentioned steps. I didn't test it on iOS or the web.

connectprabhjeet avatar Feb 15 '22 22:02 connectprabhjeet

I also i am facing same issue i solve by adding enableForceNewConnection()

 socket = io(
        'your socket url,
        OptionBuilder()
            .setTransports(['websocket'])

            //add this line
            .enableForceNewConnection() // necessary because otherwise it would reuse old connection
            .disableAutoConnect()
            .build());

ashut08 avatar Feb 24 '22 07:02 ashut08

maybe a little stupid, socket_io_client caches and reuses socket objects by default, Closing the socket also does not delete the cache, So the listeners set every time you connect will be added to the same socket object, resulting in duplicate callbacks,

Also I suspect this will cause a memory leak,

AoEiuV020 avatar May 28 '22 17:05 AoEiuV020

Same issues here in version 2.0.0

hatemragab avatar Nov 05 '22 21:11 hatemragab

Same issue here. When I disconnect and connect again it fires multiple disconnect & connect events. Version: 2.0.3+1

Mamasodikov avatar Jan 24 '24 08:01 Mamasodikov