python3接收web-socket消息

1.安裝工具包

pip3 install websocket
pip3 install websocket-client

2.代碼

ws = create_connection("ws://192.168.1.111:8000/message_transfer_test/websocket/topic")
ws.send("test")

while True:
    print("嘗試接受消息")
    result = ws.recv()
    print(str(result))

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章