[Twisted-Python] Basic twisted question

Johann Borck johann.borck at densedata.com
Sat Jul 29 11:04:39 MDT 2006


Torsten Irländer wrote:

>Continuing this way I
>would end up with many small protocols doing one single task, and
>I'm not sure If this is a good approach. 
>  
>
It sounds like you'd need to switch between those protocols while beeing
connected if you want to be able to do several operations, this is not
the way to use twisted protocol classes - of course it's ok to work with
inheritance,  but for one protocol, like IMAP, you'll want one protocol
class that does all operations (inherited or else). The http protocol
class in twisted for example is responsible for GET, POST, HEAD and all
other Request types, and is not split up into different classes for each
of these cases. Mind that the protocol usually will, once instatiated
from the Factory, stay till the end of that connection, serving
subsequent requests, and it'd be of great overhead and hard to implement
to exchange it each time another operation is requested. So, one
class/leaf of your inheritance tree will have to be able to do all the
operations of the protocol you implement.
A different use case would be switching from one protocol to another,
juice is a protocol that supports this explicitly, you can establish the
connection using juice and then switch to a protocol of your choice, fex
after authentication is done, but each, juice and the other protocol
will be responsible for the whole set of their operations.

hth, Johann






More information about the Twisted-Python mailing list