[Twisted-Python] Help With Twisted as a Client (newbie warning)
I'm trying to get a better handle on how to write a client using twisted that would react to a GUI. What I am wanting to do is to somehow be able to work with xmlclient (which is based in sux.XMLParser) so I can write to the transport. Here is the connection code: <snip> # Overrides the protocol.XlientFactory with a bit of reconnect code and sets # the protocol to xmlclient factory = CUClientFactory() factory.clients = [] sslFactory = ClientContextFactory() application = service.Application("xmlclient") reactor.connectSSL("__example__.com", 1026, factory, sslFactory) </snip> Is there a way I can access xmlxlient inside application? Is there a different way I should send data to the server? I can send data if I explicitly say so inside xmlclient, but what I am wanting to do is to send it due to outside sources (like a button click or key press). Something like this: <bad code> application.xmlparser.transport.write("testing") </bad code> I've spent a few hours searching through google and the examples/docs but haven't found out how to do this (or even if it is the right line of thinking). All help is greatly appreciated! Thanks, Steve
On Thu, 2005-02-17 at 11:25 -0500, Steve Milner wrote:
factory.clients = [] sslFactory = ClientContextFactory() application = service.Application("xmlclient") reactor.connectSSL("__example__.com", 1026, factory, sslFactory) </snip>
Is there a way I can access xmlxlient inside application?
The application object is not used for that (and certainly can't be used if it doesn't have a reference to the factory, it doesn't magically get one). Hand a reference to the factory to whichever objects wishes to control the instance.
Itamar Shtull-Trauring wrote:
On Thu, 2005-02-17 at 11:25 -0500, Steve Milner wrote:
factory.clients = [] sslFactory = ClientContextFactory() application = service.Application("xmlclient") reactor.connectSSL("__example__.com", 1026, factory, sslFactory) </snip>
Is there a way I can access xmlxlient inside application?
The application object is not used for that (and certainly can't be used if it doesn't have a reference to the factory, it doesn't magically get one). Hand a reference to the factory to whichever objects wishes to control the instance.
Thanks for the reply. I'm not sure I compleatly follow what you mean. Doing the following doesn't seem to work as it yeilds [Failure instance: Traceback: exceptions.AttributeError, xmlclient instance has no __call__ method ..... <snip> factory = ClientFactory() factory.clients = [] sslFactory = ClientContextFactory() client = xmlclient() factory.protocol = client application = service.Application(client) </snip> I also tried <snip> factory = ClientFactory() factory.clients = [] sslFactory = ClientContextFactory() client = xmlclient() factory.protocol = xmlclient application = service.Application(client) </snip> which connects but seems to be using a different instance of the xmlclient object. How can I get access to the xmlclient object inside the factory? Thanks! Steve
Hello List, I'm still stuck at mainly the same point. I've noticed that inside the class itself I can call transport.write and it writes to the server, but if I try to access it outside the class (even through a function) it gives an attribute error (AttributeError: 'NoneType' object has no attribute 'write'). I'm a bit lost. All help is much appreciated. --- factory = CUClientFactory() factory.clients = [] sslFactory = ClientContextFactory() factory.protocol = xmlclient client = xmlclient() application = service.Application(client) reactor.connectSSL("server", 1026, factory, sslFactory) client.transport.write('ya') reactor.run() ---- Itamar Shtull-Trauring wrote:
On Thu, 2005-02-17 at 11:25 -0500, Steve Milner wrote:
factory.clients = [] sslFactory = ClientContextFactory() application = service.Application("xmlclient") reactor.connectSSL("__example__.com", 1026, factory, sslFactory) </snip>
Is there a way I can access xmlxlient inside application?
The application object is not used for that (and certainly can't be used if it doesn't have a reference to the factory, it doesn't magically get one). Hand a reference to the factory to whichever objects wishes to control the instance
participants (2)
-
Itamar Shtull-Trauring
-
Steve Milner