python - Waiting online, please ask me how to process the data returned by this machine.
伊谢尔伦
伊谢尔伦 2017-05-18 11:00:32
0
3
583

The following is the data returned from a machine

import socketserver  # 导入socketserver模块
class MyServer(socketserver.BaseRequestHandler):  # 创建一个类,继承自socketserver模块下的BaseRequestHandler类
    def handle(self):  
        while 1:
            conn = self.request
            addr = self.client_address
            while 1:
                accept_data = conn.recv(1024)
                #accept_data = int('0x4',16)
                print(accept_data)
                print(accept_data.decode('utf-8'))

                if accept_data == "byebye":
                    break
                send_data = bytes(input(">>>>>"))
                conn.sendall(send_data)
            conn.close()

if __name__ == '__main__':
    sever = socketserver.ThreadingTCPServer(("192.168.0.110", 10001),MyServer) 
    sever.serve_forever() 

## 如果我直接打印 那么结果是: 而且奇葩的是还杂带了 byte 和 数字日期的,
b'JYX\x01\xac\x00\x1b\x00\x08\x00\x02\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02\x00\x06\x00\x0b\x00\x04\x00\x13\x00\x01\x00\x04\x00\x05\x00\x04\x00\x04\x00\x04\x00\x03\x00\x05\x00\x03\x00\x03\x00\x05\x00\x05\x00\x04\x00\x02\x00\x05\x00\x05\x00/*T\xe8\x00\x00\x00\x0b03  03\xe5\x85\xa8\xe8\xa1\x80cTnI/BNP/DDtest2017-04-20 09:27:1430.05ng/mLcTnI0.001.005.0pg/mLBNP0.0100.00.050mg/LDD0.0000.300XYJ'
##如果用utf-8还是其他 都直接报错了
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xac in position 4: invalid start byte
这个情况 应该怎么处理呢 , 
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
左手右手慢动作

This depends on the communication protocol, it may be a customized protocol

You have to ask the server administrator

大家讲道理

Looking at the data, I guess I need to use struct to decompress it!

漂亮男人

Go to whoever sent it, or see if there is an agreement document. It may be the agreed upon solution.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!