Hi Aymeric, 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
It works pretty well, very efficient. 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. Have a nice day. Ludovic Gasc (GMLudo) http://www.gmludo.eu/ On 9 Aug 2015 21:50, "Aymeric Augustin" <[email protected]> wrote: > Hello, > > I’m maintaining a library for building websocket servers (mainly). Before > shutting down, the server should perform a closing handshake on open > connections. I assume many other protocols with long-lived connections have > similar requirements. > > The most natural solution would to inherit asyncio.Server and to extend > close() and wait_closed() appropriately. Unfortunately there’s no way to > tell create_server() to use a custom Server class. > > Adding a kwarg: create_server(…, server_class=Server) looks like a > straightforward solution but it wouldn’t solve the problem completely. > Indeed it’s the protocol instance tied to each connection that knows what > should be done before closing its connection. But the protocol instances > and the server instance don't know about each other. > > As you can see on > https://github.com/aaugustin/websockets/commit/8e5a3954d62d01e2201aedaf4fe366d67e6af2c3#diff-a548b853d665035e6e62944845d0a575L220 > I > worked around the issue by: > > 1. instantiating my custom Server class — but it isn’t functional until > step 4 > 2. using it in the protocol factory so that the protocol instances can > register themselves with the server > 3. calling create_server() > 4. inserting the resulting asyncio.Server into my custom Server instance — > thus completing its initialization > > I’m not happy with the “delayed initialization” pattern. I wish there was > a better way. > > Has anyone else encountered a similar issue? Have you found a better > solution? Could asyncio’s APIs be enhanced in this area? > > Thanks! > > -- > Aymeric. > > > >
