[Twisted-Python] How to forcibly disconnect PB client?
David Guaraglia
dguaraglia at gmx.de
Thu Aug 25 11:02:21 EDT 2005
Hi Steve,
Well, in that case you could override connectionMade and connectionLost
in your protocol to append 'self' to a list in the factory. You don't
even need to subclass the factory if you are careful enough (this means,
if you check that the list exists before doing anything). Anyway, the
simplest thing would be to declare the list in a sublcass of
PBServerFactory.
Could be something like this:
class MyPBFactory(PBServerFactory):
protocol = MyBroker
connections = []
....
class MyBroker(Broker):
def connectionMade(...):
self.factory.connections.append(self)
def connectionLost(...):
self.factory.connections.remove(self)
Then you just use 'factory.connections' to look up for your particular
connection, and do a 'loseConnection()" on it. I'm not pretty sure, but
I think some of the protocols do even have this kind of connections list
built in, but looking into the documentation it does seem that
PBServerFactory is not one of those.
Hope it helps,
David
Steve Freitas wrote:
>Hi David,
>
>Thanks for the reply. I'm aware of using loseConnection() from inside
>the protocol, but I'm using PBServerFactory. So I'm looking for a way to
>choose an arbitrary PB client that's already connected and logged in
>(cred) through that factory and kill the connection -- in other words,
>of all the clients that may be connected to that factory, I need to know
>how to get the transport that I want, so I can call loseConnection() on
>it.
>
>If I need to subclass PBServerFactory, that's fine, but I'm hoping to
>find something a little more direct.
>
>Thanks,
>
>Steve
>
>On Thu, 2005-08-25 at 11:12 -0300, David Guaraglia wrote:
>
>
>>Hi Steve,
>>
>>It depends, if you decide you should disconnect the client while
>>processing data in the Protocol, then you can just
>>"self.transport.loseConnection()".
>>
>>(e.g):
>>class MyProt(Protocol):
>> dataReceived(data):
>> if data <> "hello":
>> self.transport.loseConnection()
>> else:
>> ....
>>
>>So the most important question is: where do you decide that you should
>>disconnect the client?
>>
>>Hope this helps,
>>
>>David
>>
>>Steve Freitas wrote:
>>
>>
>>
>>>Hi,
>>>
>>>In some cases I need to force a client to disconnect. Is there some
>>>factory call that I can use to do this? On the client side, I know I can
>>>use factory._broker.transport.loseConnection(), but on the server side,
>>>though I've looked at the source a bit, I'm not sure how to get at the
>>>correct transport.
>>>
>>>Thanks!
>>>
>>>Steve
>>>
>>>
>>>
>>>
More information about the Twisted-Python
mailing list