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

disconnect issue : Closure: (dynamic) => Null

Open wupengbigMarker opened this issue 3 years ago • 10 comments

everytime when I try to connect with server with socket.io. The socket.io will show the disconnect status and error :Unhandled Exception: Converting object to an encodable object failed: Closure: (dynamic) => Null, the error was located at package:socket_io_common/…/parser/parser.dart // json data if (null != obj['data']) { str += json.encode(obj['data']); } after this, socket.io will connect success. I don't understand why it happened like this,here is my code

    Map<String,dynamic> query = {
    };
    query.addAll(_params);
    _channel = IO.io(_url, IO.OptionBuilder()
                              .setQuery(query)
                              .setTransports(['websocket'])
                              // .disableAutoConnect()
                              .enableForceNewConnection()
                              .build());
    _channel.onConnect((data){
      isConnected = true;
      if(data != null){
        debugPrint('socket successs ******************:$data');
      }
    });

    
    _channel.onError((data){
      debugPrint('error:$data');
    });
    _channel.onConnectError((data){
      debugPrint('connect_error:$data');
      _channel.connect();
    });

    _channel.onDisconnect((data){
      // String info = _decoder.convert(data);
      debugPrint('disconnect======$data');
      _channel.connect();
    });

wupengbigMarker avatar Jan 20 '22 10:01 wupengbigMarker

same !!!!

Ashkan-Oliaie avatar Jan 27 '22 18:01 Ashkan-Oliaie

which version are you using?

jumperchen avatar Jan 29 '22 03:01 jumperchen

My case was a server-side error I assume ,after I spend a day searching , it got fixed all by itself but we switched to server v2* Client v*1

Ashkan-Oliaie avatar Jan 29 '22 07:01 Ashkan-Oliaie

@jumperchen hi there, I use the 1.0.2, My flutter verison is 2.8.1

wupengbigMarker avatar Feb 08 '22 09:02 wupengbigMarker

@wupengbigMarker which Socket server version are you using? v2.*, v3.*, or v4.*?

jumperchen avatar Feb 08 '22 10:02 jumperchen

@wupengbigMarker which Socket server version are you using? v2.*, v3.*, or v4.*? v2*

wupengbigMarker avatar Feb 14 '22 03:02 wupengbigMarker

sorry, do I have to upgrade socket server @jumperchen

wupengbigMarker avatar Feb 14 '22 03:02 wupengbigMarker

@wupengbigMarker from the info. - https://github.com/rikulo/socket.io-client-dart#version-info, it should be okay, do you have any reproducable example?

jumperchen avatar Feb 14 '22 03:02 jumperchen

My case was a server-side error I assume ,after I spend a day searching , it got fixed all by itself but we switched to server v2* Client v*1

hey,bro how did you fix it

wupengbigMarker avatar Feb 24 '22 09:02 wupengbigMarker

im getting this issues. did any one solve it ?

khalilalilahmar avatar Sep 12 '23 08:09 khalilalilahmar