A Web server in Twisted
Starting from this post that was triggered by this one I decided to do the same thing using Twisted Matrix.
Again the basic task is to write a webserver (the original poster was surprised in finding out how 'easy' it is to write a web server using .Net 2).
This is my solution:
from twisted.internet import reactor
from twisted.web2 import server, resource, channel, http
import webbrowser
PORT = 8080
class Page(resource.Resource):
addSlash = True
def render(self, ctx):
return http.Response(stream="""
<html><body><h1>This is the HTML body</h1></body></html>
""")
s = server.Site(Page())
reactor.listenTCP(PORT, channel.HTTPFactory(s))
webbrowser.open("http://%s:%d" % ("localhost", PORT))
reactor.run()
Easy isn't it?
6 Comments:
http://blogs.ugidotnet.org/puntorete/archive/2005/11/30/30816.aspx#31033
very cool post
post more informative content like the previous one
Chennai-Coimbatore
Nice post and blog
of course is easy, and it can be a useful option. You really resolved me a problem with your post.
This comment has been removed by the author.
Post a Comment
<< Home