我使用以下命令将Integer从Java客户端发送到Python服务器:
outputStream.writeInt(5);
在服务器上:
_id = self.request.recv(4)
我得到了:
Name | Type| Value
_id | str | '\x00\x00\x00\x05'
我如何解码它并将其转换回Integer?
发布于 2012-10-07 04:12:42
您可以使用python struct
module对其进行解码。
>>> import struct
>>> struct.unpack('>i', '\x00\x00\x00\x05')
(5,)
>i
模式需要一个大端有符号整数(4字节)。
https://stackoverflow.com/questions/12763428
复制相似问题