Home:ALL Converter>How to write a web server using twisted?

How to write a web server using twisted?

Ask Time:2011-04-01T21:37:15         Author:gath

Json Formatter

How do i write a simple http web server using twisted framework?

I want a web server that can receive http request and return a response to the client.

Am going through the twisted documentation and am kinda confused (maybe am just lazy), but it does not look very direct on how to do this, especially how does the twisted server receive the request parameters?

This is my effort...

from twisted.web import proxy, http
from twisted.internet import reactor
from twisted.python import log
from twisted.protocols import basic
import sys
log.startLogging(sys.stdout)

class InformixProtocol(basic.LineReceiver):
    def lineReceived(self, user):
        self.transport.write("Hello this is twisted web server!")
        self.transport.loseConnection()

class ProxyFactory(http.HTTPFactory):
    #protocol = proxy.Proxy
    protocol = InformixProtocol

reactor.listenTCP(8080, ProxyFactory())
reactor.run()

Thanks

Gath

Author:gath,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/5514162/how-to-write-a-web-server-using-twisted
yy