I want to write http server with socket io. What I need:
request --> socket io ask -> socket io answer -> response
On http request, I send message to socket io client and wait response message from socket io. Then send this message as http response or timeout. Here "getting started" code, which I want to adopt.
from aiohttp import web
import socketio
sio = socketio.AsyncServer()
app = web.Application()
sio.attach(app)
async def index(request):
sio.emit('ask', 'some data')
# here I want wait socket io answer
return web.Response(..., content_type='text/plain')
@sio.on('connect', namespace='/chat')
def connect(sid, environ):
print("connect ", sid)
@sio.on('answer', namespace='/chat')
async def answer(sid, data):
# here I want send response to index or timeout
...
@sio.on('disconnect', namespace='/chat')
def disconnect(sid):
print('disconnect ', sid)
app.router.add_get('/', index)
if __name__ == '__main__':
web.run_app(app)
I dont understund how to link http part with socket io