Twisted

From air
Jump to: navigation, search

Twisted is an event-driven networking engine written in Python (MIT license)

Protocols : HTTP (WS ?, REST ?), SMTP, POP3, IMAP, SSHv2, DNS, ...

Docs

Examples

Web Server

from twisted.web import server, resource
from twisted.internet import reactor

class HelloResource(resource.Resource):
    isLeaf = True
    numberRequests = 0
    
    def render_GET(self, request):
        self.numberRequests += 1
        request.setHeader("content-type", "text/plain")
        return "I am request #" + str(self.numberRequests) + "\n"

reactor.listenTCP(8080, server.Site(HelloResource()))
reactor.run()