简体   繁体   中英

Tornado async request timeout - how to check that user is still connected

I'm trying to code a web chat using the tornado.

The client (user) sends a long post request, during which I send him messages in response. But I am having problems with checking whether the user is online.

When a user sign out or simply close the tab / browser - everything is simple, executed on_connection_close() and I understand that it is disconnected, but if the client lost the Internet connection , then on_connection_close does not work .

How can I check, whether the user is online?

You might want to take look at tornadio2 which is Tornado+Socket.io, and implement multiplex connection , one to handle to push messages, the other is to ping the server so that you can check if the client is still connected or not.

The multiplex does not open multiple connections but uses the single connection to virtually connect to different Handlers. Look at multiplexed.py line 66.

class RouterConnection(SocketConnection):
    __endpoints__ = {'/chat': ChatConnection,
                 '/ping': PingConnection}

The multiplex example is also an sample chat application

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM