zuobijiancedaima
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

22 lines
615 B

from flask import Flask, render_template
from flask_socketio import SocketIO, emit, Namespace
from threading import Thread, Event
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app, cors_allowed_origins="*")
class MyCustomNamespace(Namespace):
def on_connect(self):
print('Client connected')
def on_disconnect(self):
print('Client disconnected')
def on_message(self, message):
emit('response', {'data': 'Got it!'}, broadcast=True)
socketio.on_namespace(MyCustomNamespace('/test'))
if __name__ == '__main__':
socketio.run(app, debug=True)