Dart Socket侦听器跳过响应数据

时间:2018-12-04 08:23:51

标签: dart flutter

使用dart-sdk版本:-2.0.0-edge.46ab040e589adc5200370dec7952ce5150850822

通过以下程序与服务器连接,同时接收响应侦听器会跳过一些数据(例如:检查以下服务器响应deta1和data2是否已正确接收到data3,如果我们在来自服务器代码的data3之前睡了1秒钟则表示睡眠正常)

遵循客户代码

import 'dart:io';
import 'dart:core';
import 'dart:typed_data';
void main() async{
    try
    {
        const Duration ReceiveTimeout = const Duration(milliseconds: 5000);
        await Socket.connect("localhost",8081).then((socket) {
            socket.setOption(SocketOption.tcpNoDelay, true);
            socket.timeout(ReceiveTimeout);
            socket.listen((data) {
                List packetData=(new Uint8List.fromList(data).buffer.asUint8List());
                print(packetData); //printing response
            });
            socket.add([255,10,81,0,1,2,5,53,50,51,51,54]); //sending Request
        }).catchError((e) {
        });
    }
    catch (e)
    {
        print("error:");
    }
}

跟随服务器响应 data1,data2和data3服务器发送标头。

byte[] data1=new byte[]{127, 77, 0, 101, 0, 1, 2, 39, 75, 5, 53, 50, 51, 51, 54, 48, 126, 40, 0, 122, 66, 41, 0, 125, 30, 0, 0, 76, 53, 41, 0, 124, 123, 40, 0, 122, 44, 41, 0, 124, 18, 41, 0, 38, 122, 40, 0, 80, 0, 0, 0, 46, 122, 40, 0, 20, 0, 0, 0, 60, 30, 0, 0, 122, 27, 0, 0, 122, 122, 55, 73, 0, 0, 0, 0, 20, 0, 0, 0, 0};

byte[] data2=new byte[]{127, 28, 0, 101, 0, 1, 2, 42, 26, 5, 53, 50, 51, 51, 54, 73, 34, 37, 0, 122, 98, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0};

byte[] data3=new byte[]{127, 26, 0, 101, 0, 1, 2, 12, 24, 5, 53, 50, 51, 51, 54, 32, 122, 0, 0, 35, 122, 40, 0, 20, 0, 0, 0, 1, 48};

如果有任何解决方案,请帮忙,谢谢

0 个答案:

没有答案