from twisted.internet import reactor, endpoints from twisted.web.server import Site from twisted.web.resource import Resource import time class ClockPage(Resource): isLeaf = True def render_GET(self, request): request.setHeader("Content-Type", "text/plain; charset=utf-8") return ( ("%s" % (time.ctime(),)) .encode('utf-8') ) resource = ClockPage() factory = Site(resource) endpoint = endpoints.TCP4ServerEndpoint(reactor, 8880) endpoint.listen(factory) reactor.run()