[Twisted-Python] twisted.internet.udp woes
Toni Andjelkovic
toni at soth.at
Mon Feb 3 07:14:55 MST 2003
Itamar Shtull-Trauring wrote on Sat, Feb 01 2003 (11:39:08 -0500):
> listenUDP does not accept factories. I'll add an assert to test for
> this. until then, read the docs - twistedmatrix.com/documents/howto/udp
Here's a patch for doc/examples/echoserv.py, according to the
docs:
Index: echoserv.py
===================================================================
RCS file: /cvs/Twisted/doc/examples/echoserv.py,v
retrieving revision 1.7
diff -u -U1 -r1.7 echoserv.py
--- echoserv.py 20 Jul 2002 13:30:44 -0000 1.7
+++ echoserv.py 3 Feb 2003 14:05:08 -0000
@@ -17,4 +17,3 @@
-from twisted.internet.protocol import Protocol, Factory
-from twisted.internet import udp
+from twisted.internet.protocol import Protocol, DatagramProtocol, Factory
@@ -24,7 +23,14 @@
-class Echo(Protocol):
+class EchoTCP(Protocol):
def dataReceived(self, data):
"As soon as any data is received, write it back."
+ print "received %r from %s" % (data, self.transport.getPeer())
self.transport.write(data)
+class EchoUDP(DatagramProtocol):
+ def datagramReceived(self, data, peer):
+ "As soon as any data is received, write it back."
+ print "received %r from %s" % (data, peer)
+ self.transport.write(data, peer)
+
### Persistent Application Builder
@@ -40,6 +46,6 @@
factory = Factory()
- factory.protocol = echoserv.Echo
+ factory.protocol = echoserv.EchoTCP
app = Application("echo")
app.listenTCP(8000,factory)
- app.listenUDP(8000, factory)
+ app.listenUDP(8000, echoserv.EchoUDP())
app.save("start")
Cheers,
--
Toni Andjelkovic
<toni at soth.at>
More information about the Twisted-Python
mailing list