[Twisted-Python] Multiple client handling...

Jean-Paul Calderone exarkun at divmod.com
Fri Aug 11 08:59:35 EDT 2006

On Fri, 11 Aug 2006 08:44:21 -0400, Grebekel <grebekel at gmail.com> wrote:
>Greetings fellow writters of Twisted code. I've been looking for some
>answers about Twisted but Twisted's docs seem to be of a twisted
>nature. Perhaps I've been looking in the wrong places.
>I'd like my server to serve multiple clients, and to achieve this I'd
>need to know to which client deliver a specific message.
>-How does a Twisted server handle multiple client connections?

This question is pretty vague, so I'm not sure which particular answer
you're looking for.

Applications developed with Twisted employ cooperative multitasking by
frequently releasing execution control to an event loop inside Twisted.
Servers handle multiple clients by dispatching events from each client
from this loop to application code.

The simplest Twisted server (for example, <http://twistedmatrix.com/projects/core/documentation/examples/simpleserv.py>) is already capable of handling multiple clients.

>-How can such a server deliver messages from a client to another (codewise)?

However you like.  You may want to subclass ServerFactory and implement
client tracking logic which allows any one of your Protocol instances to
acquire a reference to another client's Protocol instance so that it can
inspect it or invoke methods on it.

>-Any samples or tutorials online?

Examples of passing messages between different clients connect to a single
server?  None really spring to mind, perhaps because such a thing wouldn't
demonstrate any Twisted APIs not demonstratable by a similar example which
only handled a single client.

If you're feeling brave, you might look at twisted.words.service, which is
not intended as an example to teach Twisted, but which passes quite a few
messages between different clients connected to one server.


More information about the Twisted-Python mailing list