[Twisted-Python] PB release connection
Jasper Phillips
jasper at peak.org
Sat Sep 25 17:28:49 MDT 2004
On Sat, 25 Sep 2004, Uwe C. Schroeder wrote:
[snip]
> Now I'd like to be able to get rid of a specific client (which holds a
> remote-reference to MyPerspective). With the old pb api there was a way to
> do call perspective.broker.transport.loseConnection(), which I was using
> on the client side to end the connection.
>
> I can't see anything like this with the new API that would allow me to
> initiate the "kick off" from the server side.
>
> Can this be done? What would be the propper way to release a connection from
> the server side?
>
> Thanks for any enlightenment.
>
> Uwe
I don't know what the "proper" way to release a connection is, but
"perspective".broker.transport.loseConnection() works for me, where
"perspective" is whatever name you assign to the arg of the "connected"
callback attached to PBClientFactory.login()
Here's a minimal snippet of what I use, cutting out code specific to my
purposes.
class NetworkClient( pb.Referenceable ):
def __init__( self ):
self.remote = None
def connect( self, ipAddress, port, user, password ):
factory = pb.PBClientFactory()
reactor.connectTCP( ipAddress, port, factory )
defer = factory.login( credentials.UsernamePassword( user, password),
client=self )
defer.addCallbacks( self.connected, self.connectFailled )
return defer
def disconnect( self ):
self.remote.broker.transport.loseConnection()
def connected( self, perspective ):
print "Connect Succeeded to:", self.remote
self.remote = perspective
self.remote.notifyOnDisconnect( self.disconnected )
def disconnected( self, perspective ):
print "Connection Severed"
-Jasper
More information about the Twisted-Python
mailing list