Skip to content

Instantly share code, notes, and snippets.

@getnamo
Created October 30, 2018 23:15
Show Gist options
  • Save getnamo/531421d4c1382f35059e9de257c1fbfa to your computer and use it in GitHub Desktop.
Save getnamo/531421d4c1382f35059e9de257c1fbfa to your computer and use it in GitHub Desktop.
from aiohttp import web
import socketio
from colorama import init, Fore
init(autoreset=True)
sio = socketio.AsyncServer()
app = web.Application()
sio.attach(app)
async def index(request):
with open('index.html') as f:
return web.Response(test=f.read(), content_type='text/html')
@sio.on('connect', namespace="/")
def connect(sid, data):
print(Fore.RED + "connect ", sid)
@sio.on('test', namespace="/")
async def message(sid, data):
print(Fore.GREEN + "message << ", data)
await sio.emit('reply', ["Hi I'm the server", str(sid)])
@sio.on('disconnect', namespace="/")
def disconnect(sid):
print(Fore.RED + 'disconnect', sid)
app.router.add_get('/', index)
if __name__ == '__main__':
web.run_app(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment