0
Follow
0
Followers

Can you tell me a little bit about the use of long connections in websocket modules in Python?

Created: 2021-05-02 23:28:35, Updated on: 2021-05-02 23:31:12
comments   2
hits   908
import websocket

def on_message(wsapp, message):
    print(message)

def on_ping(wsapp, message):
    print("Got a ping!")

def on_pong(wsapp, message):
    print("Got a pong! No need to respond")

wsapp = websocket.WebSocketApp("wss://stream.meetup.com/2/rsvps",
  on_message=on_message, on_ping=on_ping, on_pong=on_pong)
    wsapp.run_forever(ping_interval=60, ping_timeout=10)

How can I extract the data returned to on_message from the outside? (not print out) Why does the code after the wwsapp.run_forever ((ping_interval=60, ping_timeout=10) bar not execute? I've got a lot of people who don't understand Python, so I hope God will give me a call.

More content
All comments
avatar of 小草
The grass
Set up a global variable. See Dial function, which can be used directly in Python.
2021-05-05 20:32:56
avatar of flyju
flyju
Thank you.
2021-05-06 11:49:06