rikulo / socket.io-client-dart

socket.io-client-dart: Dartlang port of socket.io-client https://github.com/socketio/socket.io-client
https://quire.io
MIT License
674 stars 184 forks source link

Error when using emitWithAck #42

Closed ramsestom closed 4 years ago

ramsestom commented 4 years ago

I am trying to use this lib but it doesn't seem to work I tried with a really simple example like this:

import 'package:socket_io_client/socket_io_client.dart' as IO;

main(List<String> arguments) {

Logger.root.level = Level.ALL; 
  Logger.root.onRecord.listen((record) {
    print('${record.level.name}: ${record.time}: ${record.message}');
  });

IO.Socket _socket = IO.io("http://192.168.8.100:4040", <String, dynamic>{ 
    'transports': ['websocket']
 });

  _socket.emitWithAck("authenticate", {"strategy":"local", "email":"test@yahoo.fr", "password":"test69"}, ack: (result){
        print("Return res: $result");
        List jsar = json.decode(result);
            if (jsar.length == 1) { //returned an error message
          print("Authentication error");
        }
        else {
          String jsdata = jsar[1] ?? ""; 
          print("Authentication data: $jsdata");
        }
      });
}

but it is throwing an error. Here is the exception call stack:

Object.noSuchMethod (dart:core-patch/object_patch.dart:51) Function._apply (dart:core-patch/function_patch.dart:10) Function.apply (dart:core-patch/function_patch.dart:31) Socket.onack (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_client-0.9.5\lib\src\socket.dart:323) Socket.onpacket (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_client-0.9.5\lib\src\socket.dart:248) EventEmitter.emit. (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_common-0.9.0+5\lib\src\util\event_emitter.dart:52) List.forEach (dart:core-patch/growable_array.dart:283) EventEmitter.emit (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_common-0.9.0+5\lib\src\util\event_emitter.dart:51) Manager.ondecoded (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_client-0.9.5\lib\src\manager.dart:321) EventEmitter.emit. (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_common-0.9.0+5\lib\src\util\event_emitter.dart:52) List.forEach (dart:core-patch/growable_array.dart:283) EventEmitter.emit (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_common-0.9.0+5\lib\src\util\event_emitter.dart:51) Decoder.add (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_common-0.9.0+5\lib\src\parser\parser.dart:159) Manager.ondata (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_client-0.9.5\lib\src\manager.dart:312) EventEmitter.emit. (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_common-0.9.0+5\lib\src\util\event_emitter.dart:52) List.forEach (dart:core-patch/growable_array.dart:283) EventEmitter.emit (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_common-0.9.0+5\lib\src\util\event_emitter.dart:51) Socket.onPacket (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_client-0.9.5\lib\src\engine\socket.dart:484) Socket.setTransport. (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_client-0.9.5\lib\src\engine\socket.dart:306) EventEmitter.emit. (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_common-0.9.0+5\lib\src\util\event_emitter.dart:52) List.forEach (dart:core-patch/growable_array.dart:283) EventEmitter.emit (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_common-0.9.0+5\lib\src\util\event_emitter.dart:51) Transport.onPacket (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_client-0.9.5\lib\src\engine\transport\transport.dart:135) Transport.onData (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_client-0.9.5\lib\src\engine\transport\transport.dart:128) IOWebSocketTransport.addEventListeners. (c:\Development\Flutter\SDK.pub-cache\hosted\pub.dartlang.org\socket_io_client-0.9.5\lib\src\engine\transport\io_websocket_transport.dart:64) _RootZone.runUnaryGuarded (dart:async/zone.dart:1314) _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336) _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263) _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:764) _StreamController._add (dart:async/stream_controller.dart:640) _StreamController.add (dart:async/stream_controller.dart:586) new _WebSocketImpl._fromSocket. (dart:_http/websocket_impl.dart:1141) _RootZone.runUnaryGuarded (dart:async/zone.dart:1314) _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336) _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263) _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68) _EventSinkWrapper.add (dart:async/stream_transformers.dart:15) _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:334) _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:229) _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120) _RootZone.runUnaryGuarded (dart:async/zone.dart:1314) _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336) _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263) _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:764) _StreamController._add (dart:async/stream_controller.dart:640) _StreamController.add (dart:async/stream_controller.dart:586) _Socket._onData (dart:io-patch/socket_patch.dart:1829) _RootZone.runUnaryGuarded (dart:async/zone.dart:1314) _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336) _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263) _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:764) _StreamController._add (dart:async/stream_controller.dart:640) _StreamController.add (dart:async/stream_controller.dart:586) new _RawSocket. (dart:io-patch/socket_patch.dart:1377) _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:897) _microtaskLoop (dart:async/schedule_microtask.dart:41) _startMicrotaskLoop (dart:async/schedule_microtask.dart:50) _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116) _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173)

and the Log from the lib is as follow:

FINE: 2019-11-20 00:23:56.001133: readyState closed FINE: 2019-11-20 00:23:56.005139: opening http://192.168.8.100:4040 FINE: 2019-11-20 00:23:56.009135: creating transport "websocket" FINE: 2019-11-20 00:23:56.048133: setting transport websocket FINE: 2019-11-20 00:23:56.049133: connect attempt will timeout after 20000 FINE: 2019-11-20 00:23:56.054139: readyState opening FINE: 2019-11-20 00:23:56.055133: emitting packet with ack id 0 #Error thrown here. The rest of the log is printed only when the program is killed FINE: 2019-11-20 00:23:56.171132: socket receive: type "open", data "{"sid":"5A3hRkmhTPSJheS_AAAT","upgrades":[],"pingInterval":25000,"pingTimeout":5000}" FINE: 2019-11-20 00:23:56.182133: socket open FINE: 2019-11-20 00:23:56.182133: open FINE: 2019-11-20 00:23:56.184133: cleanup FINE: 2019-11-20 00:23:56.187132: transport is open - connecting FINE: 2019-11-20 00:23:56.189134: socket receive: type "message", data "0" FINE: 2019-11-20 00:23:56.201133: writing packet {type: 2, data: [authenticate, {strategy: local, email: test@yahoo.fr, password: test69}], options: {compress: false}, id: 0, nsp: /} FINE: 2019-11-20 00:23:56.202133: encoding packet {type: 2, data: [authenticate, {strategy: local, email: test@yahoo.fr, password: test69}], options: {compress: false}, id: 0, nsp: /} FINE: 2019-11-20 00:23:56.205132: encoded {type: 2, data: [authenticate, {strategy: local, email: test@yahoo.fr, password: test69}], options: {compress: false}, id: 0, nsp: /} as 20["authenticate",{"strategy":"local","email":"test@yahoo.fr","password":"test69"}] FINE: 2019-11-20 00:23:56.206132: flushing 1 packets in socket FINE: 2019-11-20 00:23:57.385134: socket receive: type "message", data "30[null,{"accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6ImFjY2VzcyJ9.eyJpYXQiOjE1NzQyMDU4MzcsImV4cCI6MTU3NDI5MjIzNywiYXVkIjoiaHR0cHM6Ly95b3VyZG9tYWluLmNvbSIsImlzcyI6ImZlYXRoZXJzIiwic3ViIjoiMSIsImp0aSI6IjMxYTI4NmE4LTlhZWYtNDhkZS1iZmQ2LWJlZjk3MDFlYWE0ZSJ9.8OAhWPG-IiHRGOZJmXU3XBWnAeySa4qhvE47GGtbmuA","authentication":{"strategy":"local"},"user":{"id":"1","email":"test@yahoo.fr","googleId":null,"facebookId":null,"deviceUuid":null,"male_gender":null,"birthdate":null,"city":null,"country":null,"position":null,"langs":null,"disabled":null,"parent":null,"last_connection":null,"createdAt":"2018-08-03T19:05:48.043Z","updatedAt":"2018-08-03T19:05:48.043Z"}}]" FINE: 2019-11-20 00:23:57.389134: calling ack 0 with [null, {accessToken: eyJhbGciOiJIUzI1NiIsInR5cCI6ImFjY2VzcyJ9.eyJpYXQiOjE1NzQyMDU4MzcsImV4cCI6MTU3NDI5MjIzNywiYXVkIjoiaHR0cHM6Ly95b3VyZG9tYWluLmNvbSIsImlzcyI6ImZlYXRoZXJzIiwic3ViIjoiMSIsImp0aSI6IjMxYTI4NmE4LTlhZWYtNDhkZS1iZmQ2LWJlZjk3MDFlYWE0ZSJ9.8OAhWPG-IiHRGOZJmXU3XBWnAeySa4qhvE47GGtbmuA, authentication: {strategy: local}, user: {id: 1, email: test@yahoo.fr, googleId: null, facebookId: null, deviceUuid: null, male_gender: null, birthdate: null, city: null, country: null, position: null, langs: null, disabled: null, parent: null, last_connection: null, createdAt: 2018-08-03T19:05:48.043Z, updatedAt: 2018-08-03T19:05:48.043Z}}] Exited (sigint)

Strange thing is that even if I call a simple emit function instead of emitWithAck, like this:

_socket.emit("authenticate", {"strategy":"local", "email":"test@yahoo.fr", "password":"test69"});

no error is thrown by the app but the log still hang on after the "readyState opening" message and the rest of the log is only printed when the app is killed... So here is the log I have in this case:

FINE: 2019-11-20 00:23:56.001133: readyState closed
FINE: 2019-11-20 00:23:56.005139: opening http://192.168.8.100:4040
FINE: 2019-11-20 00:23:56.009135: creating transport "websocket"
FINE: 2019-11-20 00:23:56.048133: setting transport websocket
FINE: 2019-11-20 00:23:56.049133: connect attempt will timeout after 20000
FINE: 2019-11-20 00:23:56.054139: readyState opening
**#Log print hang on infinitely here untill the app is killed**
FINE: 2019-11-20 00:23:56.055133: emitting packet with ack id 0
FINE: 2019-11-20 00:23:56.171132: socket receive: type "open", data "{"sid":"5A3hRkmhTPSJheS_AAAT","upgrades":[],"pingInterval":25000,"pingTimeout":5000}"
FINE: 2019-11-20 00:23:56.182133: socket open
FINE: 2019-11-20 00:23:56.182133: open
FINE: 2019-11-20 00:23:56.184133: cleanup
FINE: 2019-11-20 00:23:56.187132: transport is open - connecting
FINE: 2019-11-20 00:23:56.189134: socket receive: type "message", data "0"
FINE: 2019-11-20 00:23:56.201133: writing packet {type: 2, data: [authenticate, {strategy: local, email: test@yahoo.fr, password: test69}], options: {compress: false}, id: 0, nsp: /}
FINE: 2019-11-20 00:23:56.202133: encoding packet {type: 2, data: [authenticate, {strategy: local, email: test@yahoo.fr, password: test69}], options: {compress: false}, id: 0, nsp: /}
FINE: 2019-11-20 00:23:56.205132: encoded {type: 2, data: [authenticate, {strategy: local, email: test@yahoo.fr, password: test69}], options: {compress: false}, id: 0, nsp: /} as 20["authenticate",{"strategy":"local","email":"test@yahoo.fr","password":"test69"}]
FINE: 2019-11-20 00:23:56.206132: flushing 1 packets in socket
FINE: 2019-11-20 00:23:57.385134: socket receive: type "message", data "30[null,{"accessToken":"eyJhbGciOiJIUzI1NiIsInR5cCI6ImFjY2VzcyJ9.eyJpYXQiOjE1NzQyMDU4MzcsImV4cCI6MTU3NDI5MjIzNywiYXVkIjoiaHR0cHM6Ly95b3VyZG9tYWluLmNvbSIsImlzcyI6ImZlYXRoZXJzIiwic3ViIjoiMSIsImp0aSI6IjMxYTI4NmE4LTlhZWYtNDhkZS1iZmQ2LWJlZjk3MDFlYWE0ZSJ9.8OAhWPG-IiHRGOZJmXU3XBWnAeySa4qhvE47GGtbmuA","authentication":{"strategy":"local"},"user":{"id":"1","email":"test@yahoo.fr","googleId":null,"facebookId":null,"deviceUuid":null,"male_gender":null,"birthdate":null,"city":null,"country":null,"position":null,"langs":null,"disabled":null,"parent":null,"last_connection":null,"createdAt":"2018-08-03T19:05:48.043Z","updatedAt":"2018-08-03T19:05:48.043Z"}}]"
FINE: 2019-11-20 00:23:57.389134: calling ack 0 with [null, {accessToken: eyJhbGciOiJIUzI1NiIsInR5cCI6ImFjY2VzcyJ9.eyJpYXQiOjE1NzQyMDU4MzcsImV4cCI6MTU3NDI5MjIzNywiYXVkIjoiaHR0cHM6Ly95b3VyZG9tYWluLmNvbSIsImlzcyI6ImZlYXRoZXJzIiwic3ViIjoiMSIsImp0aSI6IjMxYTI4NmE4LTlhZWYtNDhkZS1iZmQ2LWJlZjk3MDFlYWE0ZSJ9.8OAhWPG-IiHRGOZJmXU3XBWnAeySa4qhvE47GGtbmuA, authentication: {strategy: local}, user: {id: 1, email: test@yahoo.fr, googleId: null, facebookId: null, deviceUuid: null, male_gender: null, birthdate: null, city: null, country: null, position: null, langs: null, disabled: null, parent: null, last_connection: null, createdAt: 2018-08-03T19:05:48.043Z, updatedAt: 2018-08-03T19:05:48.043Z}}]
Exited (sigint)

any idea of what might be the issue and how to solve it?

ramsestom commented 4 years ago

OK found the origin of the issue. the socket.onack() method is using the Function.apply method. But when this method is passed a List , each element of this List is considered an argument of this function (https://api.dartlang.org/stable/2.6.1/dart-core/Function/apply.html). So if the object returned by the ack is a List=a json array (which was my case), the callback do not behave as expected To fix this bug, line 323 of the socket.dart file needs to be changed to: Function.apply(ack, [packet['data']]); so that even if the result of the ack is a List, it would be treated as a unique single object to be passed as argument to the ack callback.

Bytheway, The emitBuffered function is bugged also. It should be:

emitBuffered() {
    var i;
    for (i = 0; i < this.receiveBuffer.length; i++) {
      List args = this.receiveBuffer[i];
      if (args.length > 2) {
        Function.apply(super.emit, [args.first, args.sublist(1)]);
      } else {
        Function.apply(super.emit, args);
      }
    }
    this.receiveBuffer = [];

    for (i = 0; i < this.sendBuffer.length; i++) {
      this.packet(this.sendBuffer[i]);
    }
    this.sendBuffer = [];
  }

Same fix should also probably be applied to other 'Function.apply' calls (I didn't inspect the whole lib code, only the socket.dart file so the same issue can potentially afect other functions in other files) where function argument type are not known (=are dynamic) and can potentially be a List

jumperchen commented 4 years ago

@ramsestom I released a 0.9.6 version, please give it a try.

ramsestom commented 4 years ago

Thanks. I have seen you fix and it is pretty much the changes I have done in my local copy so it should work ;) FYI, your fix https://github.com/rikulo/socket.io-client-dart/commit/0e1e3abef4d61e4cf5a6241dacb5db701b172918 has an unecessary is List test, you can simplify it by wrapping packet['data'] into a list each time (that would work even if packet['data'] isn't a List so no need to test for it and the code would be simpler)

jumperchen commented 4 years ago

okay, thanks.

jumperchen commented 4 years ago

@ramsestom After I take some times to test this issue, the original implementation works well with our socket.io dart server without any error in either List type or single element which is passed by server's ack function. So, which socket.io server are you using? I am afraid its protocols may be different from our assumption.

jumperchen commented 4 years ago

I refix it again for both nodejs and dart server version.

ramsestom commented 4 years ago

Thanks. I am using the node.js (feathersjs) version for my server

Zony-Zhao commented 4 years ago

I'm using 0.9.11. same issue here.

 _socket.once('connect', (_) {
    logger.i("connect");
    _socket.emitWithAck(
        messageName,
        {
          "fromUserId": "5f58dc9a0af1377e642f14b9",
          "toSessionId": "5f58dc9a0af1377e642f14ba",
          "content": "here hello",
          "timestamp": 123132,
          "type": 0
        },
        ack: () {},
        binary: false);
  });

error

E/flutter ( 5858): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: Closure call with mismatched arguments: function 'createConnection.<anonymous closure>.<anonymous closure>'
E/flutter ( 5858): Receiver: Closure: () => Null
E/flutter ( 5858): Tried calling: createConnection.<anonymous closure>.<anonymous closure>(true)
E/flutter ( 5858): Found: createConnection.<anonymous closure>.<anonymous closure>() => Null
E/flutter ( 5858): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter ( 5858): #1      Function._apply (dart:core-patch/function_patch.dart:11:30)
E/flutter ( 5858): #2      Function.apply (dart:core-patch/function_patch.dart:34:12)
E/flutter ( 5858): #3      Socket.onack (package:socket_io_client/src/socket.dart:318:18)
E/flutter ( 5858): #4      Socket.onpacket (package:socket_io_client/src/socket.dart:240:9)
E/flutter ( 5858): #5      EventEmitter.emit.<anonymous closure> (package:socket_io_common/src/util/event_emitter.dart:52:14)
E/flutter ( 5858): #6      List.forEach (dart:core-patch/growable_array.dart:302:8)
E/flutter ( 5858): #7      EventEmitter.emit (package:socket_io_common/src/util/event_emitter.dart:51:11)
E/flutter ( 5858): #8      Manager.ondecoded (package:socket_io_client/src/manager.dart:308:5)
E/flutter ( 5858): #9      EventEmitter.emit.<anonymous closure> (package:socket_io_common/src/util/event_emitter.dart:52:14)
E/flutter ( 5858): #10     List.forEach (dart:core-patch/growable_array.dart:302:8)
E/flutter ( 5858): #11     EventEmitter.emit (package:socket_io_common/src/util/event_emitter.dart:51:11)
E/flutter ( 5858): #12     Decoder.add (package:socket_io_common/src/parser/parser.dart:159:14)
E/flutter ( 5858): #13     Manager.ondata (package:socket_io_client/src/manager.dart:299:13)
E/flutter ( 5858): #14     EventEmitter.emit.<anonymous closure> (package:socket_io_common/src/util/event_emitter.dart:52:14)
E/flutter ( 5858): #15     List.forEach (dart:core-patch/growable_array.dart:302:8)
E/flutter ( 5858): #16     EventEmitter.emit (package:socket_io_common/src/util/event_emitter.dart:51:11)
E/flutter ( 5858): #17     Socket.onPacket (package:socket_io_client/src/engine/socket.dart:465:11)
E/flutter ( 5858): #18     Socket.setTransport.<anonymous closure> (package:socket_io_client/src/engine/socket.dart:290:34)
E/flutter ( 5858): #19     EventEmitter.emit.<anonymous closure> (package:socket_io_common/src/util/event_emitter.dart:52:14)
E/flutter ( 5858): #20     List.forEach (dart:core-patch/growable_array.dart:302:8)
E/flutter ( 5858): #21     EventEmitter.emit (package:socket_io_common/src/util/event_emitter.dart:51:11)
E/flutter ( 5858): #22     Transport.onPacket (package:socket_io_client/src/engine/transport/transport.dart:127:5)
E/flutter ( 5858): #23     Transport.onData (package:socket_io_client/src/engine/transport/transport.dart:121:5)
E/flutter ( 5858): #24     IOWebSocketTransport.addEventListeners.<anonymous closure> (package:socket_io_client/src/engine/transport/io_websocket_transport.dart:67:7)
E/flutter ( 5858): #25     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5858): #26     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5858): #27     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5858): #28     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 5858): #29     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 5858): #30     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter ( 5858): #31     _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter ( 5858): #32     _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter ( 5858): #33     new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1145:21)
E/flutter ( 5858): #34     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5858): #35     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5858): #36     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5858): #37     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 5858): #38     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 5858): #39     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:69:11)
E/flutter ( 5858): #40     _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
E/flutter ( 5858): #41     _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:338:23)
E/flutter ( 5858): #42     _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:232:46)
E/flutter ( 5858): #43     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:121:24)
E/flutter ( 5858): #44     _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 5858): #45     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5858): #46     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5858): #47     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 5858): #48     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 5858): #49     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter ( 5858): #50     _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter ( 5858): #51     _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter ( 5858): #52     _Socket._onData (dart:io-patch/socket_patch.dart:2020:41)
E/flutter ( 5858): #53     _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 5858): #54     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5858): #55     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5858): #56     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter ( 5858): #57     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter ( 5858): #58     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter ( 5858): #59     _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter ( 5858): #60     _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter ( 5858): #61     new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1556:33)
E/flutter ( 5858): #62     _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1052:14)
E/flutter ( 5858): #63     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 5858): #64     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter ( 5858): 

And as same as ramsestom, it was totally ok with just emit().

Zony-Zhao commented 4 years ago

Ok, I found the problem. In the ack parameter function, you need to set the right parameter you wish to get from server, and it can't be omitted. If you don't know what you would get, use dynamic.

 ack: (dynamic acked) {
      logger.i(acked);
    }