[Twisted-Python] ProducerConsumerProxy problem

Pietro Niccoli piemail at tiscali.it
Wed Nov 4 15:54:11 EST 2009

I'm trying to write a simple echo server but with control flow. The program
should send back all the data it receives from a client, but if one of the
clients that are connected stop accepting the data that is sent back, my
program should tell it to stop sending data too, for preventing to run out
of memory. 
I've seen that twisted offers an iConsumer and iProducer classes, so my
class should implement both of them. I know how to write the producer part,
but I still having trouble in telling twisted that my class is a consumer
for the transport. This is because usually in a program, whenever there is
data available, the dataRecived function of the program is called, passing
the data to it, so I don't know who I can pass as a producer for my echo
I know that there's a class called BasicProducerConsumerProxy in pcp that
seems to do my job, but I'm stuck in making it understand that "transport"
is both a consumer and a producer.
The code should be something like this:

Echo = protocols.pcp.BasicProducerConsumerProxy(self.transport) #register
transport as a consumer Echo.registerProducer(self.transport, True)
#register transport as a producer

But it doesn't work. Can you help me? An example will be greatly
appreciated. Thanks.


More information about the Twisted-Python mailing list