[Twisted-Python] Perspective Broker and keeping track of connected clients
phil at bubblehouse.org
Tue Oct 17 14:52:03 EDT 2006
On Oct 17, 2006, at 1:13 PM, Yi Qiang wrote:
> I am using PB to expose some methods and objects remotely.
> However, I need to keep track of the people who are connected to
> the PB server via IP address (I've thought about using
> authentication, but I would like anonymous access as well). My
> requirement is that at any given moment, I need to know which ip's
> are connected to the server. Is this possible using PB/Twisted?
> If so how? I have the Twisted book and have looked for tutorials
> on the web, but neither seem to address this issue.
I actually needed this feature myself recently. It may or may not
work for your needs, but I needed something that would 'catch' an IP
address before the connection actually commenced (I also needed to be
able to ban addresses).
The solution was a simple subclass of PBServerFactory
def buildProtocol(self, addr):
# Your custom code can go here, perhaps storing
# addr.host somewhere fun
proto = self.protocol(0)
proto.factory = self
Then you can catch disconnects in your Perspective class...
More information about the Twisted-Python