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 Anonymous said...

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

 
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.

 
At 3:40 PM, Blogger Unknown said...

This comment has been removed by the author.

 

Post a Comment

<< Home