Asyncio gunicorn worker with websockets support.
pip install gaiohttp-websocket
gunicorn -k gaiohttp_websocket.AiohttpWebsocketWorker wsgi:app
This will provide wsgi.websocket
environment variable for websocket connections, it's an instance of aiohttp.web.WebSocketResponse
.
This example can be used in any wsgi compatible application.
ws = environ['wsgi.websocket']
while True:
msg = yield from ws.receive()
ws.send_str("received: %s" % msg.data)