Valentino Volonghi's Weblog

Greetings mercenaries!

Sunday, December 04, 2005

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:

At 1:17 PM, Anonymous Michele Bersani said...

http://blogs.ugidotnet.org/puntorete/archive/2005/11/30/30816.aspx#31033

 
At 11:42 AM, Blogger Part Time Jobs Online said...

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

 
At 11:14 AM, Anonymous website design New York City said...

very cool post

 
At 9:26 AM, Blogger Mani said...

post more informative content like the previous one
Chennai-Coimbatore

 
At 1:43 PM, Anonymous Nettsivut arco said...

Nice post and blog

 
At 4:49 PM, Anonymous viagra online said...

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