开发者

How to write a web server using twisted?

开发者 https://www.devze.com 2023-02-21 17:00 出处:网络
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.

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 (ma开发者_StackOverflowybe 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

0

精彩评论

暂无评论...
验证码 换一张
取 消