1234567891011121314151617181920212223242526 |
- from flask import Flask, render_template
- from flask_socketio import SocketIO
-
- app = Flask(__name__)
- app.config['SECRET_KEY'] = 'your_secret_key' # Replace with your own secret key
-
- socketio = SocketIO(app)
-
- @app.route('/')
- def index():
- return render_template('index.html')
-
- @socketio.on('connect')
- def handle_connect():
- print('Client connected')
-
- @socketio.on('message')
- def handle_message(data):
- print('Received message:', data)
- socketio.emit('response', 'Server received your message: ' + data)
-
-
-
- if __name__ == '__main__':
- # socketio.run(app, debug=True)
- socketio.run(app,host='0.0.0.0', debug=True,allow_unsafe_werkzeug=True)
|