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

Laurens Van Houtven _ at lvh.cc
Fri Mar 1 09:31:43 EST 2013


Well, you'd presumably have a connection to each of the servers in the form
of a client factory and a protocol instance. Then, every time you get a
message, you figure out which protocol instance you want (the one for the
appropriate server) and send a message to it. You could do that with
self.transport.write, of course, but it would be much easier to just use a
ready-made RPC thing.

One such RPC thing is AMP, which comes with Twisted. You can read more
about it here:

http://amp-protocol.net/
https://twistedmatrix.com/documents/current/core/howto/amp.html

You will probably end up having a command like HandlePacket or something
(presumably you can come up with a more apt domain-specific name), and
something close to
self.servers[serverFor(packet.origin)].callRemote(HandlePacket,
packet.data), or whatever.

I realize this is still pretty vague and high level, so feel free to ask
more questions about the parts that are unclear :)


On Thu, Feb 28, 2013 at 10:59 PM, Benjamin BERTRAND <beenje at gmail.com>wrote:

> Hi,
>
> I have to replace a piece of software that sniffs the traffic on one
> interface. It gets different messages that are each associated to a
> specific emitter.
> On the same machine, one server is started for each emitter (on a
> different port).
> And the application is just supposed to use the proper server to send the
> messages captured (to a client on another machine).
>
> Not sure if it's clear, but basically if I have 2 emitters A and B, I'll
> start 2 servers (a and b).
> My sniffer will get messages A1, A2, B1, B2, B3...
> I have to pass messages A1, A2 to server a, that will just send them to
> the client (if it is connected of course).
> And B1, B2, B3 to server b.
> I don't need any buffering. If no client is connected, messages captured
> are just discarded.
>
> To sniff the network, I want to use pylibpcap or pcapy.
> I found this example to make it work with twisted:
> http://dound.com/2009/09/integrating-twisted-with-a-pcap-based-python-packet-sniffer/
>
> Starting several servers that use the same protocol is not a problem.
> But how do I pass the messages captured to the right server?
> How do I make the link between the function sniffing the network and the
> servers?
>
> Thanks
>
> Benjamin
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



-- 
cheers
lvh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20130301/8867f1fa/attachment.htm 


More information about the Twisted-Python mailing list