Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 45 lines (29 sloc) 1.184 kb
3aa6e69 @thijstriemstra Remove copyright, refs #728
thijstriemstra authored
1 # Copyright (c) The PyAMF Project.
8744307 @thijstriemstra Merge as-rst-661: move the examples project into the doc folder of the p...
thijstriemstra authored
2 # See LICENSE.txt for details.
3
4 """
db2aec7 @thijstriemstra Merge udp-howto-720: Add howto for the UDP example.
thijstriemstra authored
5 Test Twisted server for Adobe AIR 2.0's UDP support.
8744307 @thijstriemstra Merge as-rst-661: move the examples project into the doc folder of the p...
thijstriemstra authored
6
3aa6e69 @thijstriemstra Remove copyright, refs #728
thijstriemstra authored
7 Based on examples from http://twistedmatrix.com/documents/current/core/howto/udp.html
8744307 @thijstriemstra Merge as-rst-661: move the examples project into the doc folder of the p...
thijstriemstra authored
8 """
9
10 from pyamf import register_class
11 from pyamf.amf3 import ByteArray
12
13 from twisted.internet.protocol import DatagramProtocol
14 from twisted.internet import reactor
15
16
17 class HelloWorld(object):
18
19 def __repr__(self):
20 return "<%s msg='%s' time=%s />" % (self.__class__.__name__, self.msg,
21 self.time)
22
23
24 class EchoUDPServer(DatagramProtocol):
25
26 def datagramReceived(self, data, (host, port)):
27 ba = ByteArray(data)
28 result = ba.readObject()
29 print " received %s from %s:%d" % (result, host, port)
30
31 self.transport.write(data, (host, port))
32
33
34 if __name__ == "__main__":
35 alias = "org.pyamf.examples.air.udp.vo.HelloWorld"
36 register_class(HelloWorld, alias)
37 print "Registered alias '%s' for class '%s'" % (alias, HelloWorld.__name__)
38
39 port = 55555
40 print 'Server started listening on port', port
41
42 server = EchoUDPServer()
43 reactor.listenUDP(port, server)
db2aec7 @thijstriemstra Merge udp-howto-720: Add howto for the UDP example.
thijstriemstra authored
44 reactor.run()
Something went wrong with that request. Please try again.