[Twisted-Python] How to send message to all connected clients

Jp Calderone exarkun at intarweb.us
Sun Jul 20 19:40:41 MDT 2003


On Mon, Jul 21, 2003 at 11:30:03AM +1000, Minh Luu wrote:
> Hi,
> 
> Could I have some advice on how to send a message to all connected clients.
> 
> Where do I keep the list of the client connections - in the sub-class of Protocol
> or in the sub-class of Factory?

  Definitely in your Factory subclass.  You can add Protocol instances to
the list in your buildProtocol() method and remove them either the Factory's
clientConnectionLost() method or the Protocol's connectionLost() method.

> 
> Do I call the write method for each client connection or there is a better way in twisted
> to send a message to all the clients or a group of clients.
> 

  If you're using TCP, doing a write() on each connection is pretty much a
requirement.  If you're using UDP, you might be able to manage something
better with multicast (but since you mentioned factories, I'm guessing
you're not using UDP).

  Hope this helps,

  Jp

-- 
Somewhere, something incredible is waiting to be known.
                -- Carl Sagan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20030720/29dc6e62/attachment.sig>


More information about the Twisted-Python mailing list