- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- # Filename: UdpServer.py
- #
- # Author:
- # Modify data:
- # Create data:
- # Modify Author:
-
- import sys
- import socket
- from twisted.internet.protocol import DatagramProtocol
- from twisted.internet import reactor
-
- def decorator(aclass):
- class newclass(DatagramProtocol):
- def __init__(self):
- self.wrapped = aclass()
- def datagramReceived(self, data, (host, port)):
- self.wrapped.process(data, (host,port));
- return newclass
-
- @decorator
- class Bird:
- def __init__(self):
- print 'Bird'
-
- def process(self, data, (host, port)):
- print 'Bird process: ',data
-
- @decorator
- class fish:
- def __init__(self):
- print 'fish'
-
- def process(self, data, (host, port)):
- print 'fish process: ',data
-
- if __name__ == "__main__":
- reactor.listenUDP(8000, Bird())
- reactor.listenUDP(9000, fish())
- reactor.run()#!/usr/bin/pythonint GetDepth(BinaryTreeNode * pRoot)
-