[Twisted-Python] IP address, server

Erik van Blokland erik at letterror.com
Fri Jun 20 09:26:20 EDT 2003


Hello,

a humble question for a nudge in the right direction. I'm
utterly new to twisted, but I have a lot of experience in
python. I'm trying to get a tiny working demo to play with
and learn. I've installed twisted 1.0.5 on a Mac G3 running
10.2.6 OSX. Python 2.3b1. runtests seems to work.

The tiny http server script works when I take a browser on
the same machine as the server and look at
http://127.0.0.1:801, I get the expected result, so the
server is alive. When I take a look from a different machine
using the local IP address of the server http://10.0.0.5:801
I get no response. Other services over my network to the
server work fine. Do I need to do more, listen to a specific
port, tell the server the IP address? Is this supposed to
work and the problem lies elsewhere, OS perhaps (would be
good to know too)

This is my test script:

from twisted.web import resource
from twisted.web import server
from twisted.internet import reactor

HTTP_PORT = 801

class MyServer(resource.Resource):
    isLeaf = True
    def render(self, httprequest):
        hdr = httprequest.getAllHeaders()
        html = '<html><body>Have a nice day
%d</body></html>'
        httprequest.write(html)

        httprequest.setHeader('Content-Length', len(html))
        httprequest.setHeader('Content-Type', 'html/plain')
        httprequest.setResponseCode(200)

        httprequest.finish()
        
aserver = MyServer()
site = server.Site(aserver)
reactor.listenTCP(HTTP_PORT, site)
reactor.run()



Any pointers would be appreciated. Sorry if this is a dumb
question..

Thanks,
Erik van Blokland




More information about the Twisted-Python mailing list