[Twisted-Python] Detecting idle connection with perspective broker
![](https://secure.gravatar.com/avatar/16e4d8fb4cc933d579f9fb9362a81204.jpg?s=120&d=mm&r=g)
Hi there, I wrote a small server application with PB but now I have some problem with client disconnection. When I have a idle connection, the logout method at server never is called (this method let me have a list of current logged users) and then client appears always connected to server. I can see the same issue with the chatserver example from perspective broker doc with detached method. class ChatRealm: implements(portal.IRealm) def requestAvatar(self, avatarID, mind, *interfaces): assert pb.IPerspective in interfaces avatar = User(avatarID) avatar.server = self.server avatar.attached(mind) return pb.IPerspective, avatar, lambda a=avatar:a.detached(mind) How can I detect that idle connection clients to call detached method? Thanks! -- Aquest missatge ha estat analitzat per MailScanner a la cerca de virus i d'altres continguts perillosos, i es considera que està net.
![](https://secure.gravatar.com/avatar/b70690e672a9e5968adc126d9dd0c16d.jpg?s=120&d=mm&r=g)
A simple solution could be to implement a ping method with client and have server ping client once every N seconds. At the same time, fire a delayed call for N+5 seconds. if delayed call is executed first, drop connection. -- Konrads Smelkovs Applied IT sorcery. 2010/4/30 Gabriel González <gabriel@cttc.upc.edu>
![](https://secure.gravatar.com/avatar/16e4d8fb4cc933d579f9fb9362a81204.jpg?s=120&d=mm&r=g)
Thanks! that works for me, now I set a Timeout in server and I can check if client is connected every 10 seconds. But now I have a last question about what's the better way to delete the User(avatar) instance when the logout is done. In my logout method I delete database entries about the disconnected user, but how can I do to clean User(avatarID) instance and where I have to do that. Thanks Gabriel. On Fri, 2010-04-30 at 14:23 +0300, Konrads Smelkovs wrote:
-- Aquest missatge ha estat analitzat per MailScanner a la cerca de virus i d'altres continguts perillosos, i es considera que est� net.
![](https://secure.gravatar.com/avatar/16e4d8fb4cc933d579f9fb9362a81204.jpg?s=120&d=mm&r=g)
Ok, and there's any method to know when this object will be collected or if really don't have more references?. How can I know what users are logged for PB to test if these objects have been deleted correctly? thanks, Gabriel On Tue, 2010-05-11 at 13:42 +0000, exarkun@twistedmatrix.com wrote:
-- Aquest missatge ha estat analitzat per MailScanner a la cerca de virus i d'altres continguts perillosos, i es considera que està net.
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 12 May, 09:36 am, gabriel@cttc.upc.edu wrote:
The realm (which you supply) creates all the user objects. So you're in complete control. If you want your realm to track all the users it has created, it can. Jean-Paul
![](https://secure.gravatar.com/avatar/16e4d8fb4cc933d579f9fb9362a81204.jpg?s=120&d=mm&r=g)
ok, thanks! Gabriel. On Thu, 2010-05-13 at 13:56 +0000, exarkun@twistedmatrix.com wrote:
-- Aquest missatge ha estat analitzat per MailScanner a la cerca de virus i d'altres continguts perillosos, i es considera que està net.
![](https://secure.gravatar.com/avatar/b70690e672a9e5968adc126d9dd0c16d.jpg?s=120&d=mm&r=g)
A simple solution could be to implement a ping method with client and have server ping client once every N seconds. At the same time, fire a delayed call for N+5 seconds. if delayed call is executed first, drop connection. -- Konrads Smelkovs Applied IT sorcery. 2010/4/30 Gabriel González <gabriel@cttc.upc.edu>
![](https://secure.gravatar.com/avatar/16e4d8fb4cc933d579f9fb9362a81204.jpg?s=120&d=mm&r=g)
Thanks! that works for me, now I set a Timeout in server and I can check if client is connected every 10 seconds. But now I have a last question about what's the better way to delete the User(avatar) instance when the logout is done. In my logout method I delete database entries about the disconnected user, but how can I do to clean User(avatarID) instance and where I have to do that. Thanks Gabriel. On Fri, 2010-04-30 at 14:23 +0300, Konrads Smelkovs wrote:
-- Aquest missatge ha estat analitzat per MailScanner a la cerca de virus i d'altres continguts perillosos, i es considera que est� net.
![](https://secure.gravatar.com/avatar/16e4d8fb4cc933d579f9fb9362a81204.jpg?s=120&d=mm&r=g)
Ok, and there's any method to know when this object will be collected or if really don't have more references?. How can I know what users are logged for PB to test if these objects have been deleted correctly? thanks, Gabriel On Tue, 2010-05-11 at 13:42 +0000, exarkun@twistedmatrix.com wrote:
-- Aquest missatge ha estat analitzat per MailScanner a la cerca de virus i d'altres continguts perillosos, i es considera que està net.
![](https://secure.gravatar.com/avatar/607cfd4a5b41fe6c886c978128b9c03e.jpg?s=120&d=mm&r=g)
On 12 May, 09:36 am, gabriel@cttc.upc.edu wrote:
The realm (which you supply) creates all the user objects. So you're in complete control. If you want your realm to track all the users it has created, it can. Jean-Paul
![](https://secure.gravatar.com/avatar/16e4d8fb4cc933d579f9fb9362a81204.jpg?s=120&d=mm&r=g)
ok, thanks! Gabriel. On Thu, 2010-05-13 at 13:56 +0000, exarkun@twistedmatrix.com wrote:
-- Aquest missatge ha estat analitzat per MailScanner a la cerca de virus i d'altres continguts perillosos, i es considera que està net.
participants (3)
-
exarkun@twistedmatrix.com
-
Gabriel González
-
Konrads Smelkovs