Skip to content

Instantly share code, notes, and snippets.

@walpolsh
Last active October 14, 2021 13:34
Show Gist options
  • Select an option

  • Save walpolsh/e4db1cb0d4f51c3852ef3720a29cc16a to your computer and use it in GitHub Desktop.

Select an option

Save walpolsh/e4db1cb0d4f51c3852ef3720a29cc16a to your computer and use it in GitHub Desktop.
from flask import Flask, request, jsonify
from flask_socketio import SocketIO, emit
from flask_cors import CORS
app = Flask(__name__)
socketio = SocketIO(app, logger=True, engineio_logger=True, cors_allowed_origins='http://localhost:3001')
CORS(app)
@socketio.on('connect')
def on_connect():
print('connected dude')
payload = dict(data='Connected')
print(payload)
emit('log', payload, broadcast=True)
@socketio.on('message')
def handle_message(data):
print('received message: ' + data)
if __name__ == '__main__':
socketio.run(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment