[Twisted-web] Callback help client / server

Terry Jones terry at jon.es
Wed Nov 18 06:41:16 EST 2009

>>>>> "Chris" == Chris  <datarecall at hotmail.com> writes:
Chris> I am trying to figure out a way so I can access the datareceived
Chris> outside of the Echo Class so I can run operations on the data
Chris> received.

Your protocol knows when it has received something that needs to be acted
on. So the simplest possibility is to have the protocol take the action.

If that's too simple, you can have the protocol call a method on the
factory. So at some point (perhaps in dataReceived) the protocol calls
self.factory.doSomething(). Look at the source of
twisted.internet.protocols.Factory and you'll see that buildProtocol puts a
factory attribute on the newly created protocol instance.  The factory can
then implement the higher level processing. If that's still not suitable,
you can build other options by, e.g., passing something to the factory
initializer that it puts onto protocol instances for the protocol to call

Take a look at HTTPClientFactory and its HTTPPageGetter protocol in
twisted/web/client.py  for an instructive example.


More information about the Twisted-web mailing list