Created
October 30, 2018 23:15
-
-
Save getnamo/531421d4c1382f35059e9de257c1fbfa to your computer and use it in GitHub Desktop.
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
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