Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket会不停发送消息,停不下来 #27

Open
bifu123 opened this issue May 8, 2024 · 0 comments
Open

websocket会不停发送消息,停不下来 #27

bifu123 opened this issue May 8, 2024 · 0 comments

Comments

@bifu123
Copy link

bifu123 commented May 8, 2024

import websocket
import json
import requests


url = "http://192.168.66.29:8080/api/sendtxtmsg"
ws_url = "ws://192.168.66.29:8080/ws/generalMsg" 

def on_message(ws, message):
    data = json.loads(message)

   
    data1 = {
        "wxid": "cbf_4151352321",
        "content": "你好"
    }
    response = requests.post(url, json=data1)
    print(response.text)


def on_error(ws, error):
    print("Error:", error)

def on_close(ws):
    print("Connection closed")

def on_open(ws):
    print("Connection established")

# 循环建立 WebSocket 连接
ws = websocket.WebSocketApp(ws_url,
                            on_message=on_message,
                            on_error=on_error,
                            on_close=on_close)
ws.on_open = on_open
ws.run_forever()

这样会一直不停地发送“你好”,停不下来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant