twisted helloworld

来源:互联网 发布:9 9乘法口诀c语言 编辑:程序博客网 时间:2024/05/17 10:08
A simple twisted program which can be served as a helloworld of twisted.

from twisted.internet.protocol import Factory, Protocol
from twisted.internet import reactor

class QOTD(Protocol):

    def connectionMade(self):
        self.transport.write(self.factory.quote+'/r/n')
        self.transport.loseConnection()


class QOTDFactory(Factory):

    protocol = QOTD

    def __init__(self, quote=None):
        self.quote = quote or 'An apple a day keeps the doctor away'

reactor.listenTCP(8007, QOTDFactory("configurable quote"))
reactor.run(