[CentralOH] Help with Twisted Framework

Aaron Bush asb.bush at gmail.com
Thu May 28 18:14:03 CEST 2009

Does anyone on the list have experience using the twisted framework?

I am looking to pick you brain about the 'best' way to write an application
using this framework.

Here is the msg that I posted to the twisted mail list:

I have just started to look at the Twisted framework and would like to put
it to use for a new project I am working on.  Not being very familiar with
the framework and fairly new to Python in general I would like to ask a
design/architecture question.  (I have written similar applications in C but
would prefer to start this in the right direction and not write Python like

The application has the following model:

Many clients connect to the Application and prefer to leave the connection
open.  They will send messages across this connection.  They will expect to
get a message back at some point later, they do not wait for a response
(async).  The clients are already coded (legacy) and just need to send their
proprietary protocol to the new Application (written using Twisted).

The Twisted application will take the data from the clients and do some
transformation on it then send the message on to another server (3rd
party).  This connection to "another" server must be a single connection,
not one connection per client.  This connection should also be persistent
and not opened/closed for each client message sent.  Ideally if the 3rd
party server is down then I would also not accept client connections as the
messages are time sensitive and should not be stored and forwarded.  At some
point the 3rd part will send a message back and the Application will route
it back to the original source.  Basically request/reply pattern.

I have been reading through the archives and the twisted docs and have also
looked over the Hex-dump port-forwarding recipe but not found anything that
explains how to use twisted for this model.  Hex-dump is close but
opens/closes the connection to the server on each client connection.

I am thinking that there will be two Factories [and two protocols: 1) for
clients and 2) for 3rd party].  I am not sure how to best establish both the
listening factory and the client to 3rd party factory.  Once they are
established what is the preferred way in Twisted to pass a message from one
protocol to another?

Any pointers or sample code that you can offer is greatly appreciated.  I
would really like to cook this in Twisted and not go back to the C way.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/mailman/private/centraloh/attachments/20090528/00af517e/attachment.htm>

More information about the CentralOH mailing list