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.

app.py 655B

1234567891011121314151617181920212223242526
  1. from flask import Flask, render_template
  2. from flask_socketio import SocketIO
  3. app = Flask(__name__)
  4. app.config['SECRET_KEY'] = 'your_secret_key' # Replace with your own secret key
  5. socketio = SocketIO(app)
  6. @app.route('/')
  7. def index():
  8. return render_template('index.html')
  9. @socketio.on('connect')
  10. def handle_connect():
  11. print('Client connected')
  12. @socketio.on('message')
  13. def handle_message(data):
  14. print('Received message:', data)
  15. socketio.emit('response', 'Server received your message: ' + data)
  16. if __name__ == '__main__':
  17. # socketio.run(app, debug=True)
  18. socketio.run(app,host='0.0.0.0', debug=True,allow_unsafe_werkzeug=True)