[Twisted-web] Creating a hybrid server in Twisted

Glyph Lefkowitz glyph at twistedmatrix.com
Tue Apr 5 21:54:18 EDT 2011


On Apr 4, 2011, at 7:51 PM, David Bolen wrote:

> Jashank Jeremy <jashank.jeremy at optusnet.com.au> writes:
> 
>> So I'm pretty much stuck in a rut.  I don't want to totally reinvent the
>> wheel just to be able to protocol-switch; I'd prefer to make use of
>> existing code from Twisted.  How do I hijack Twisted.Web to add protocol
>> switching?
> 

> To insert your own protocol code, you want to set the "protocol"
> attribute of your Site (or HTTPFactory if using that directly)
> instance to your own "hybrid" protocol class.

It would be slightly better to override buildProtocol, because that way you can call the superclass's implementation more idiomatically.  But, the idea is the same.

Note that we'd really like to have protocol switch functionality built into Twisted proper so that you don't have to jump through all these hoops.  Please feel free to contribute patches to fix this ticket: <http://twistedmatrix.com/trac/ticket/3204>.




More information about the Twisted-web mailing list