[Twisted-Python] UDP and factories

Alex Levy mesozoic at polynode.com
Fri Aug 8 20:21:23 EDT 2003

On Fri, Aug 08, 2003 at 05:18:05PM -0600, John Janecek wrote:
> I am attempting to use DatagramProtocol with a factory
> are u supposed to use DatagramProtocol with a factory ??
> am i out to lunch ?

Yes, you are -- but don't worry, it was leftover ham sandwiches ;]
No, you do not need to use a factory for a DatagramProtocol.  Thus:

> from twisted.internet.protocol import DatagramProtocol
> from twisted.internet import reactor
> class Echo(DatagramProtocol):
>     def datagramReceived(self, data, (host, port)):
>         print "received %r from %s:%d" % (data, host, port)
>         self.transport.write(data, (host, 7000))
> reactor.listenUDP(6000,Echo())
> reactor.run()

Look at <http://twistedmatrix.com/documents/howto/udp> for more information.

Alex Levy
WWW: http://mesozoic.geecs.org
"Never let your sense of morals prevent you from doing what is right."
 -- Salvor Hardin, Isaac Asimov's _Foundation_

More information about the Twisted-Python mailing list