Last active
July 28, 2021 17:57
-
-
Save milnomada/e542a1ffc3f50849edbbb75d6e9e6907 to your computer and use it in GitHub Desktop.
Simple Socket.io application with Python and uwsgi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import socketio | |
from engineio.async_drivers import gevent | |
logging.basicConfig(level=logging.INFO) | |
sio = socketio.Server(async_mode="gevent_uwsgi", cors_allowed_origins='*', engineio_logger=True) | |
logger = logging.getLogger("socket-server") | |
@sio.on('connect', namespace='/') | |
def connect(sid, environ):ç | |
logger.info("connect {}".format(sid)) | |
sio.emit('ok', room=sid) | |
@sio.on('message', namespace='/') | |
def message(sid, data): | |
sio.emit('x-message', data=data, room=data['sid']) | |
@sio.on('disconnect', namespace='/') | |
def disconnect(sid): | |
logger.info("disconnect {}".format(sid)) | |
my_wsgi = socketio.WSGIApp(sio) | |
app = socketio.Middleware(sio, my_wsgi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment