Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用websocket客户端发送二进制数据python使用WebSocketApp(不创建连接)_Python_Websocket - Fatal编程技术网

如何使用websocket客户端发送二进制数据python使用WebSocketApp(不创建连接)

如何使用websocket客户端发送二进制数据python使用WebSocketApp(不创建连接),python,websocket,Python,Websocket,我选择WebSocketApp是因为它可以永远保持连接。不幸的是,WebSocketApp不提供ws.send_binary(),就像创建_连接一样。我想发送二进制数据消息并解码传入消息,请帮助我,以下是原始示例: import websocket def on_message(ws, message): print(message) def on_error(ws, error): print(error) def on_close(ws): print('Websoc

我选择WebSocketApp是因为它可以永远保持连接。不幸的是,WebSocketApp不提供ws.send_binary(),就像创建_连接一样。我想发送二进制数据消息并解码传入消息,请帮助我,以下是原始示例:

import websocket
def on_message(ws, message):
    print(message)
def on_error(ws, error):
    print(error)
def on_close(ws):
    print('Websocket: closed')
def on_open(ws):
    print('Websocket: open')
ws = websocket.WebSocketApp('ws://echo.websocket.org/',on_message = on_message,on_error = on_error,on_close = on_close,on_open = on_open)
ws.run_forever()
您可以使用或(
ws.send(buf,binary=True)
),两者都可以直接发送二进制数据。

试试这个:

ws.send(data, websocket.ABNF.OPCODE_BINARY)

您可以使用base64对二进制数据进行编码,并将其作为文本传输。