【问题标题】:how I do decode buffer message with struct我如何用 struct 解码缓冲区消息
【发布时间】:2020-05-20 18:15:39
【问题描述】:

我写了python套接字客户端,但是服务器返回剩余时间如何在python中解码这个结构。

    header = Buffer.from( [03, 00, 00, 00]);
    time = new Uint16Array(1);
    time[0] = remaining_time_in_sec;

    packet = Buffer.concat( [header, Buffer.from(time.buffer)]);

    this.socket.write(packet);

这个函数返回像

b'\x03\x00\x00\x00\t\x01'

【问题讨论】:

    标签: python sockets binary buffer


    【解决方案1】:

    我想解决这个问题

    返回二进制码

    b'\x03\x00\x00\x00\x0e\x01'
    
    this here packet type
    b'\x03\x00\x00\x00'
    
    unpack('h',b'\x0e\x01')
    return <======================
    270
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多