[Twisted-Python] How to forcibly disconnect PB client?

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

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

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
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

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

Ah ha! Like most of Twisted, deceptively simple. I thought, "Given the arguments of requestAvatar(), the logical place to find the broker has to be in the mind." And whaddya know, there it is. Lovely. Thanks, Glyph!
Steve

LOL, I just finished writing a lengthy mail explaining an unlikely solution!
Nice to hear you already got this done :)
David
Steve Freitas wrote:
Ah ha! Like most of Twisted, deceptively simple. I thought, "Given the arguments of requestAvatar(), the logical place to find the broker has to be in the mind." And whaddya know, there it is. Lovely. Thanks, Glyph!
Steve
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Heh, thanks for the help -- it wouldn't have been the first time I'd have come up with a complicated solution to something Twisted made easy. :-)
Thanks,
Steve
On Thu, 2005-08-25 at 12:03 -0300, David Guaraglia wrote:
LOL, I just finished writing a lengthy mail explaining an unlikely solution!
Nice to hear you already got this done :)
David
Steve Freitas wrote:
Ah ha! Like most of Twisted, deceptively simple. I thought, "Given the arguments of requestAvatar(), the logical place to find the broker has to be in the mind." And whaddya know, there it is. Lovely. Thanks, Glyph!
Steve
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

On Thu, 2005-08-25 at 07:57 -0600, Steve Freitas wrote:
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.
remoteReference.broker.transport.loseConnection()
participants (4)
-
David Guaraglia
-
Itamar Shtull-Trauring
-
Steve Freitas
-
Tommi Virtanen