python socket如何发送字节数据?

 

def send_byte():
    a = [0x10, 0x20, 0x50]
    b = ""
    for i in range(len(a)):
        b += chr(a[i])
    print repr(b)
 
    sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    sock.connect(('localhost', 8001))
    time.sleep(2)
    sock.send(b)
    print sock.recv(1024)
    sock.close()

Or use struct.pack

 

From: python socket如何发送字节数据?

你可能感兴趣的:(Python)