Python发送已知字节

时间:2018-03-02 09:30:35

标签: python sockets

我想通过网络发送已知bytes的流,例如0020ff00,但我希望在char符号的连接旁边使用其他方法。 你能为我提供另一种更优雅的方法吗? 感谢

def send_connect_request(sock):
    print('Sending connect request...')
    sock.send('' + chr(2) + chr(0) + chr(0) + chr(0) + chr(255) + chr(0))   
    # sock.shutdown(1)

更改为

def send_connect_request(sock):
    print('Sending connect request...')
    sock.send(0x0002ff00)       
    # sock.shutdown(1)

1 个答案:

答案 0 :(得分:2)

如果您知道字节数,请使用ERROR at //third_party/WebKit/Source/core/frame/BUILD.gn:170:20:Assignment had no effect. shared_library = [ ":addlib.so" ] ^----------- You set the variable "shared_library" here and it was unused before it went out of scope. 字面值:

bytes

如果您确实不想输出所有转义序列,请使用sock.send(b'\x02\x00\x00\x00\xff\x00') 构造函数以及bytes的列表:

int