I selected WebSocketApp because it can remain connected forever. Unfortunately WebSocketApp does not offer ws.send_binary() just like create_connection. I want send binary data message and decode incoming message, Please help me, here is the original example:
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()
Try this one:
ws.send(data, websocket.ABNF.OPCODE_BINARY)
You could use websockets or ws4py(ws.send(buf, binary=True)
), both can send binary data directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With