首页 > Python Socket 使用 Struct.pack 组包问题

Python Socket 使用 Struct.pack 组包问题

问题描述

数据包具体的内容

Java消息体实现代码`

public Message(String content) {
    length = new int[]{calcMessageLength(content), 0x00, 0x00, 0x00};
    code = new int[]{calcMessageLength(content), 0x00, 0x00, 0x00};
    magic = new int[]{0xb1, 0x02, 0x00, 0x00};
    this.content = content;
    end = new int[]{0x00};
}

`

发出的消息内容

Message{length=[173, 0, 0, 0], code=[173, 0, 0, 0], magic=[177, 2, 0, 0], content='type@=loginreq/username@=/ct@=0/password@=/roomid@=321358/devid@=B609634DCCFC4DD48BF085BB35B7CF97/rt@=1453874133/vk@=1e1806220f06b5402cab6486e99e42da/ver@=20150929/', end=[0]}

问题

如何使用 Python 的 struct.pack 来完成相同的功能?

【热门文章】
【热门文章】