from aiohttp import web
import socketio
import asyncio
import time
sio = socketio.AsyncServer()
app = web.Application()
sio.attach(app)
async def sendmg(interval: int):
while True:
await sio.emit('newwind', '1')
await asyncio.sleep(interval)
async def index(request):
"""Serve the client-side application."""
with open('index.html') as f:
return web.Response(text=f.read(), content_type='text/html')
@sio.event
async def connect(sid, environ):
print("connect ", sid)
@sio.event
def disconnect(sid):
print('disconnect ', sid)
app.router.add_static('/static', 'static')
app.router.add_get('/', index)
asyncio.ensure_future(sendmg(3))
web.run_app(app)
web.run_app(app)