[Twisted-Python] peer 2 peer, udp, stdio -> very confused

Jean-Paul Calderone exarkun at divmod.com
Mon Dec 4 11:37:20 EST 2006


On Mon, 4 Dec 2006 10:26:10 +0100, varname <varname at gmail.com> wrote:
>hi all,
>
>first: I have been reading the topics on this list regarding apps that
>need to be client/server at the same time, use udp, need to be able to
>react to user input while the reactor is running with much interest,
>but I'm very confused now as to how I should proceed with my own
>problem.
>
>In short: I'm trying to create a peer 2 peer application that has a
>text-based gui (commandline), driven by user input and communicates
>with other peers over udp (and occasionally over tcp, to transfer
>files).
>
>I'm just really confused over some basic concepts. Am I correct that I
>can just create a simple class extending protocol.DatagramProtocol to
>facilitate the raw udp sending / receiving?

That is how UDP works with Twisted, yes.

>Then use that in a Factory
>class (MyClientFactory) to 'layer' the p2p protocol functionality on?

Protocol factories aren't involved in UDP, since their purpose is to
expose the concept of a connection with a limited lifetime, a concept
lacking in UDP.

>Where do I put my stdio implementation then?

Standard IO is treated as a connection-oriented transport, so you
interact with it in much the same way as you would interact with a
TCP connection.  The primary difference is that instead of creating
a factory and passing it to connectTCP, you just create your protocol
and instantiate StandardIO with it.

>And am I right that the
>only thing needed for udp to work is to do a
>reactor.listenUDP(portnum, MyClientFactory()) or do I need to use two
>factory classes, one for the client 'bit' and one for the server?

Since there is only listenUDP, there's no place for a 2nd DatagramProtocol
to go.  You can manage both sending and receiving datagrams with a single
instance.

Jean-Paul




More information about the Twisted-Python mailing list