[Twisted-Python] Connection Manager

Reza Lotun reza at getpeer.com
Thu Nov 20 18:25:06 EST 2008

Hi All,

I've been thinking of implementing a connection manager in twisted. The app
I'm working on has various parts or "modules" that individually make
separate connections to various services and what not. They basically act
independently of each other - as in they're all scheduled connection calls
and what not.

I'm interested in mediating these connections through a "Dispatcher" of
sorts - what I'm thinking would be a thin wrapper over the reactor, with
extra state. One of the things the Dispatcher would do is gauge network
connection health - something like periodically attempting to ping/connect
to well known internet sites. If the connection ever degrades or fails, the
Dispatcher would change state. Fairly straightforward, conceptually at

My questions are twofold - is the general idea sound - how is such a thing
implemented elsewhere? Also, what would be the best strategy to implement
the above, if the idea is sane?

I was thinking something like this: my Dispatcher would have something like
a connectTCP call which would in turn call the reactor.connectTCP with a
special DispatcherFactory. As the returned IConnector calls
startedConnecting on the DispatcherFactory, it would check internal state,
figure out a policy and decide whether to continue with the connection and
call the passed in factory's buildProctol, or call the IConnector
stopConnecting to pause the connection attempt. If the situation improves
later on, the IConnector.connect can be called to "resume" the connection

Any feedback would be greatly appreciated.


Reza Lotun
Senior Software Engineer
GetPeer Limited
reza at getpeer.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20081120/34f4aa8a/attachment.htm 

More information about the Twisted-Python mailing list