[Twisted-Python] pb server how to get client IP address

Brian Warner warner at lothar.com
Fri Feb 13 19:36:28 EST 2004

Martin Stenhård <stenis at stenhard.net> writes:
> Yes this works find in my server for my admin interface (simple telenet
> bases) that use protocol.ServerFactory() and then use LineReceiver. 
> But how do I use getPeer() in a Perspective Broker server for example
> http://www.twistedmatrix.com/documents/examples/pbbenchserver.py

Ah, yes, that is trickier. You need to get access to the Broker object (which
is a Protocol subclass), and called methods are not generally given access to
that. The Perspective/ViewPoint -style stuff gives invoked methods access to
some initial Perspective object, but even that doesn't know who the Broker
is. The method which invokes your perspective_* method knows, but it isn't

I poked around a bit and haven't found any way to get at it. If the client
has given you access to one if its own objects (perhaps as the 'mind'
reference in the realm.requestAvatar() call), then you can use it to get the


Other than that, I don't see how to do it. The details of the connection are
a little *too* abstracted out. Maybe someone else has an idea?


PS: and no, inspect.stack()[1][0].f_locals['broker'] doesn't count..

More information about the Twisted-Python mailing list