我正在尝试解码来自Netty服务器的消息,但是我不确定是否解码的数据正确解码。我需要对dart套接字执行任何操作以使其与从netty发送的protobuf消息一起工作吗?在写任何消息之前,我还需要做任何事情吗?另外,是否每次收到数据或调用onDone时都进行解析?
Socket.connect(ip, port).then((Socket sock) {
print("Connected");
socket = sock;
socket.setOption(SocketOption.tcpNoDelay, true);
socket.listen(onReceive,
onError: (e) {
print('Server error: $e');
},
onDone: onDoneEvent,
cancelOnError: false);
});
服务器channel handlers:
p.addLast(new ProtobufVarint32FrameDecoder());
p.addLast(new MultiplePacketDecoder(decoders));
p.addLast(new ProtobufVarint32LengthFieldPrepender());
p.addLast(new ProtobufEncoder());
p.addLast(processingHandler);
哦,顺便说一句,每当我尝试解析消息时,都会出现此错误
E/flutter (25389): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
E/flutter (25389): #0 CodedBufferReader.readTag (package:protobuf/src/protobuf/coded_buffer_reader.dart:144:7)
E/flutter (25389): #1 _mergeFromCodedBufferReader (package:protobuf/src/protobuf/coded_buffer.dart:34:21)
E/flutter (25389): #2 GeneratedMessage.mergeFromBuffer (package:protobuf/src/protobuf/generated_message.dart:173:5)
E/flutter (25389 My class): #3 PacketHandler.parseFromBytes (package:chatclientflutter/backend/packethandler.dart:32:26)
E/flutter (25389 My class): #4 Client.onDoneEvent (package:chatclientflutter/backend/client.dart:77:46)
E/flutter (25389): #5 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (25389): #6 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (25389): #7 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (25389): #8 _BufferingStreamSubscription._sendDone.sendDone (dart:async/stream_impl.dart:389:13)
E/flutter (25389): #9 _BufferingStreamSubscription._sendDone (dart:async/stream_impl.dart:399:15)
E/flutter (25389): #10 _BufferingStreamSubscription._close (dart:async/stream_impl.dart:283:7)
E/flutter (25389): #11 _SyncStreamController._sendDone (dart:async/stream_controller.dart:772:19)
E/flutter (25389): #12 _StreamController._closeUnchecked (dart:async/stream_controller.dart:629:7)
E/flutter (25389): #13 _StreamController.close (dart:async/stream_controller.dart:622:5)
E/flutter (25389): #14 _Socket._onData (dart:io-patch/socket_patch.dart:1781:21)
E/flutter (25389): #15 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (25389): #16 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (25389): #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (25389): #18 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter (25389): #19 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
E/flutter (25389): #20 _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
E/flutter (25389): #21 _StreamController._add (dart:async/stream_controller.dart:640:7)
E/flutter (25389): #22 _StreamController.add (dart:async/stream_controller.dart:586:5)
E/flutter (25389): #23 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1330:35)
E/flutter (25389): #24 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:837:18)
E/flutter (25389): #25 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (25389): #26 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
答案 0 :(得分:0)
如果标题包含“ Sec-WebSocket-Extensions”,请检查标题:“ permessage-deflate; client_max_window_bits”。它不起作用。