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

Not able to recieve data on manual disconnection and Connecting.

Open gkathir15 opened this issue 4 years ago • 3 comments

Am currently using socket_io_client: 0.9.12, sice I hav not migrated to flutter 2.x, So when am connecting to the socket on the app Cold start, the socket works fine, am able to observe my custom event. So upon manual disconnection and reinitialization to connect, am not able to receive any data in my custom socket event, and am able to observe connected ping & pong events. this even occurs after the socket's dispose and disconnect is called. even on assigning null to the socket instance and reinitialization.

to resolve this after skimming through the code, within the lib\socket_io_client.dart file, It seems there is an instance maintained, so on reconnection, if the URL domain is the same, it uses multiplexing, But ideally, it should work on connecting to the same URL. but didn't,

So I am passing

 ['forceNew'] = true or
      opts['force new connection'] = true 

while initializing the socket, which simply forces a new connection. and it is working for the above-said scenario I would like to know if this is the right way, If so I can make a pull request and make the necessary changes.

gkathir15 avatar Dec 29 '21 11:12 gkathir15

I'm using socket_io_client: 2.0.0-beta.4-nullsafety.0

And I can confirm the scenario. It happens for me as well.

santhoshsail2c avatar May 04 '22 17:05 santhoshsail2c

while initializing the socket, which simply forces a new connection. and it is working for the above-said scenario I would like to know if this is the right way, If so I can make a pull request and make the necessary changes.

You mean something like this?

    final options = IO.OptionBuilder()
        .setTransports(['websocket']).setAuth({"token": token.token}).build();
    options['force new connection'] = true;
    options['forceNew'] = true;

    IO.Socket socket = IO.io(u, options);

And you attach your listeners on reconnect?

neckaros avatar Jul 05 '22 11:07 neckaros

Yes , Listeners can be either maintained or listeners can reattched. But ideally the reason I opened this issue is , it doesn't actually need to happen his way.

gkathir15 avatar Jul 07 '22 17:07 gkathir15