我使用下面的代码(从本网站复制)将数据从我的服务器发送到Google Chrome 15 +
握手成功,我也可以从客户端接收数据并对其进行解码但是当我尝试向客户端发送数据时,我收到以下错误:
无法识别的帧操作码:3
def encode_hybi(buf, opcode = 0x01):
buf = b64encode(buf)
b1 = 0x80 | (opcode & 0x0f)
payload_len = len(buf)
if payload_len <= 125:
header = struct.pack('>BB', b1, payload_len)
elif payload_len > 125 and payload_len < 65536:
header = struct.pack('>BBH', b1, 126, payload_len)
elif payload_len >= 65536:
header = struct.pack('>BBQ', b1, 127, payload_len)
return header + buf