[Twisted-Python] How to dispatch message to different servers

Tom Prince tom.prince at ualberta.net
Sat Mar 2 13:12:43 EST 2013

Benjamin BERTRAND <beenje at gmail.com> writes:

> Le 2 mars 2013 à 15:33, Laurens Van Houtven <_ at lvh.cc> a écrit :
>> I'm guessing that this is another question that will be solved as
>> soon as I see the code (perhaps you should put all your code up
>> somewhere); but all I do know is that all Deferreds buy you is an
>> abstraction for organizing callbacks; it's not a dispatch mechanism
>> (and if you're using it as one now, you do have dispatch logic, it
>> just lives somewhere else).
> The dispatch is done in the pcapDataReceived method (in the
> ServerFactory) thanks to the dictionary of deferred (using the line id
> as key).  And each line is associated to a server on a specific port.

Instead sticking a deferred in that dictionary, you could just stick the
`Oldimon` protocol instance, or the bound method (i.e. `self.sendMessage`)
in that dictionary. In which case `messageToSend` becomes obsolete,
since you don't need to rearm it each time.


More information about the Twisted-Python mailing list