[Twisted-Python] ClientFactory: implementing Request/Response with a persistent connection

Wolfgang Powisch powo at powo.priv.at
Wed Feb 2 18:01:57 MST 2011


Hello,

I need to talk to a Line-based TCP service from a Twisted Application.
The remote server will accept requests and send a response.

I do NOT want to open a NEW TCP-Connection for each request.

Are there any examples how to send concurrent requests over a single
conenction ? .. so that my module takes care of sending the next request
when the previous response has been received


Here a simple (pseudo-)example of how I would like to use my client-module:

-------------------------
xyclient = yield XyClient('127.0.0.1',1234).connect()
d1 = xyclient.send_request('GET 1')  # returns a deferred
d2 = xyclient.send_request('GET 2')  # returns a deferred
d1.addCallback(print)
d2.addCallback(print)

"Response 1"
"Response 2"
-------------------------


Later I need to enhance this to manage a Pool of connections and dispatch
requests across this pool. Does there exist something "out of the box"
for ConnectionPools ?


regards, powo








More information about the Twisted-Python mailing list