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
Indian Free Classifieds :
I like to visit your blog and it is have interesting writings about business opportunity and you can also visit website for indian free classifieds to get more ideas about online business from home and you can find more home based business opportunity to work at home in your part time at jobs online.
Indian Free Classifieds
Shipping Directory
Part Time Jobs
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.
Post a Comment
Links to this post:
Create a Link
<< Home