[Twisted-Python] Howto access protocol outside of the class
teratorn at twistedmatrix.com
Sun Feb 11 00:01:36 EST 2007
On Sat, 10 Feb 2007 16:16:06 -0600, Lee Connell <lee.a.connell at gmail.com>
> I have a class: class ForemClient(LineReceiver):
> I am using wxPython to build a GUI. I am having the hardest time trying
> access the instance of this class so I can call the transport methods
> from a
> wxPython button event. How can I make this accessible outside of the
> itself? I seen that ClientCreator could be used for this, but I can?t
> an example of using the instance outside of itself. Anyone able to help?
> chat = ClientCreator(reactor, ForemClient)
> d = chat.connectSSL("localhost", 1025, ssl.ClientContextFactory())
You already asked this same basic question two hours ago... Not sure why
you would re-phrase it here.
Anyway, the answer is to save the protocol instance when it gets created.
This happens in the buildProtocol() method on your factory.
By default, the factory creates the protocol instance and returns it to
Twisted. It's not available to user-level code directly.
So you should implement your own buildProtocol(). Have a look at
Factory.buildProtocol and duplicate the things that it does. Then you are
free to save a reference to the newly created protocol in any way you see
More information about the Twisted-Python