On 10 août 2015, at 11:38, Ludovic Gasc <[email protected]> wrote:
> I don't know all implementation details, however, we use on production for
> several daemons this implementation:
> http://aiohttp.readthedocs.org/en/latest/web.html#websockets
> <http://aiohttp.readthedocs.org/en/latest/web.html#websockets>Yes, it’s a
> lower-level alternative with a more verbose API. It was written after I
> released websockets.
FYI here’s a quick comparison of echo servers written with each library:
# websockets
@asyncio.coroutine
def handler(websocket, path):
while True:
data = yield from websocket.recv()
if message is None:
break
yield from websocket.send(data)
# aiohttp
@asyncio.coroutine
def websocket_handler(request):
ws = web.WebSocketResponse()
ws.start(request)
while True:
msg = yield from ws.receive()
if msg.tp == aiohttp.MsgType.text:
ws.send_str(msg.data)
# unsure about this one as MsgType isn't documented
elif msg.tp == aiohttp.MsgType.bytes:
ws.send_str(msg.data)
elif msg.tp == aiohttp.MsgType.close:
break
elif msg.tp == aiohttp.MsgType.error:
break
return ws
> About your specific problem, I'm not sure it's implemented in aiohttp because
> it's remember me something, however, when we stops the daemon, we use the
> bidirectional communication property of WebSockets to send a signal to the
> Web browsers to force disconnections and use another server, to try to be the
> most invisible at end user level.
In other words you’ve implemented a custom application-level closing message
because the library you’re using doesn’t implement the protocol-level closing
handshake. Truth be said, neither did mine until a few days ago ;-)
--
Aymeric.