[Twisted-Python] is twisted suitable for rfb protocol implement?

Eric Faurot eric.faurot at gmail.com
Thu Jul 27 03:06:00 EDT 2006

On 7/27/06, wang wei <wgwigw at gmail.com> wrote:
> hi, I want to implement a rfb server using twisted, but I find  rfb protocol
> maybe hard to code in twisted, since it needs read  blocks of data and
> depend on the readed value to read the next blocks. is there a good solution
> for twisted? thanks.

Twisted cannot make the protocol itself simpler to write. All it does
is to give you a framework in which you don't have to worry about
plumbing details. All you really have to do is to focus on the
protocol logic.

I don't know about this specific protocol, but you should try to think
of your protocol handler as a automaton: consider that you receive
input data that you must (usually in slices) dispatch to a specific
handler depending on your current state. The handler processes the
data, does whatever it has to, then adapts the current state as
necessary. The point is that you should define your states so that you
know how much data they need to consume to do something useful (that
is in the protocol description).

Designing your handler like this makes it very flexible, because it
naturally handles partial data, so it can be plugged on top of
anything that streams, for example a twisted connection. All you have
to do then is to write a glue Protocol that will connect
dataReceived() to your decoder input. Furthermore, it will probably be
more correct and easier to maintain, because it will very much match
the way your protocol is described on the paper.

For example, you can look at how my OggDecoder works:


The code is not always brilliant and polished, but it should give you
the idea.


More information about the Twisted-Python mailing list