[Twisted-Python] Howto access protocol outside of the class

Lee Connell lee.a.connell at gmail.com
Sun Feb 11 09:37:17 EST 2007


Sorry for double posting, must have spaced it.  Thanks for reply.

-----Original Message-----
From: twisted-python-bounces at twistedmatrix.com
[mailto:twisted-python-bounces at twistedmatrix.com] On Behalf Of Eric Mangold
Sent: Sunday, February 11, 2007 12:02 AM
To: Twisted general discussion
Subject: Re: [Twisted-Python] Howto access protocol outside of the class

On Sat, 10 Feb 2007 16:16:06 -0600, Lee Connell <lee.a.connell at gmail.com>  
wrote:

> I have a class: class ForemClient(LineReceiver):
>
>
>
> I am using wxPython to build a GUI.  I am having the hardest time trying  
> to
> 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  
> class
> itself?  I seen that ClientCreator could be used for this, but I can?t  
> find
> an example of using the instance outside of itself.  Anyone able to help?
>
>
>     chat = ClientCreator(reactor, ForemClient)
>
>     d = chat.connectSSL("localhost", 1025, ssl.ClientContextFactory())
>
>     reactor.run()

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  
fit.

Cheers,
-- 
Eric Mangold
Twisted/Win32 Co-Maintainer

_______________________________________________
Twisted-Python mailing list
Twisted-Python at twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.33/678 - Release Date: 2/9/2007
4:06 PM
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.17.33/678 - Release Date: 2/9/2007
4:06 PM
 





More information about the Twisted-Python mailing list