[Twisted-Python] writing back through open connections

Matthew Glubb matt at madebykite.com
Tue Mar 4 14:45:54 EST 2008

Hi David,

This is not the twisted way to do it. You should take a look at:


It talks about Factory classes. Essentially, your service is a Server  
Protocol Factory. When a client connects to that service, the Factory  
instance does not deal with responses to the client. Instead, the  
buildProtocol method of the Factory instance is invoked. This  
instantiates a completely new instance of your Server Protocol class.  
It is this instance (commonly, a state machine) that handles the  
logic of reacting to incoming messages from the client and responding  
to them.

You should treat your Protocol class as a completely self contained  
way of communicating solely with the client that it was instantiated  

Hope that helps,


Matthew Glubb
Technical Partner

email: matthew.glubb at madebykite.com
phone: 44 (0) 7715 754017
skype: mglubb


GPG: 96FF DE0E 0B7B 37F0 7F8D C54C E285 3D8F 5625 9244

On 4 Mar 2008, at 19:15, David Welch wrote:

> Hi,
> I'm new to twisted and I am having trouble writing back through  
> open tcp connections. In my setup I have many clients (lets say 10  
> for this example) connecting to a server running twisted. Each time  
> a new client connects I maintain that connection indefinitely and  
> it populates a list of available clients the server can talk to. I  
> want a user to select from that list and send data to that client  
> using the open connection. In this case a client won't cause an  
> event (so I can't just write back to it in say the receivedData  
> function because the client is just sitting idle waiting for data  
> to be pushed to it). The transport.write() works in the protocol  
> that handles events from the clients, but like I said the client  
> will be waiting idle until some data is sent to it (it just makes  
> the initial connection to the serve). Is there any way to see a  
> list of the open connections so I can selectively write to it? Or  
> is there another way to do this? Thanks for the help.
> Dave
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list