Echo Server

ちょっと書きたかったので。

from twisted.internet.protocol import DatagramProtocol
from twisted.python import threadable
from twisted.internet import reactor

threadable.init(1)
reactor.suggestThreadPoolSize(32)

class EchoServer(DatagramProtocol):
    def echo(self, datagram, address):
        self.transport.write(datagram, address)

    def startProtocol(self):
        print 'Started Listening'

    def datagramReceived(self, datagram, address):
        reactor.callInThread(self.echo, datagram, address)

if __name__ == '__main__':
    reactor.listenUDP(5005, EchoServer())
    reactor.run()