I am working on a chat application that uses Tornado on the backend. I used a long poll to get the number of online users and any new chat message available on the server. I opened two long contacts with the server.
It is very easy to detect when the user is connected to the network. I encoded this class, which maintains a list of (user) users who are logged on to the network. This list is easily sent to any client requesting online users (as you can see in the code below). But when the user goes offline, I do not know that, and therefore, the windowsill (user) remains the same. Therefore, even if someone goes offline, I cannot update the list of users. Please help me figure out a way by which I can delete users who are not connected (using a lengthy survey) and update the list of users.
I heard that I have to apply a certain type of polling mechanism to the list user, since the disconnect event is disabled in the tornado, unlike node.js. Please help me implement this polling mechanism. The response to the code would be much appreciated.
class OnlineHandler(BaseHandler): online = [] identifier = [] user = [] time = [] @tornado.web.asynchronous def post(self): random = self.get_argument("random", None) self.online_user(self.get_current_user(), self.retuser,random) def online_user(self, u, callback, random): cls = OnlineHandler if u not in cls.user: cls.time.append(time.time()) cls.user.append(u) else: index = cls.user.index(u) cls.time[index] = time.time() cls.online.append(callback) if random not in cls.identifier:
source share