[Twisted-Python] Small Problem -twisted web

Mike Owens stormcoder at yahoo.com
Sat Dec 13 20:44:33 EST 2003

I have written a script that runs as a Win32 service. The service runs but
when I try to connect I get a connection refused error in the browser. I am
including the source at the end. Also the call to unlistenTCP doesn't seem
to return. Anyone have any ideas?

import win32serviceutil as wsu
import win32service as ws
import win32event as we

from twisted.internet import app
from twisted.web import static, server, vhost, script

DefaultSite = r"sites\Default\documents"
my = r"sites\my\documents"
other = r"sites\other\documents"

Indices = ['index.html', 'index.rpy']

class TwistedService(wsu.ServiceFramework, object):
    _svc_name_ = "TwistedWeb"
    _svc_display_name_ = "A twisted web server"
    root = None
    Application = None
    def __init__ (self, args):
        wsu.ServiceFramework.__init__(self, args)
        self.hWaitStop = we.CreateEvent(None, 0, 0, None)
        self.root = vhost.NameVirtualHost()
        self.root.default = static.File(DefaultSite)
        pf = static.File(my)
        pf.indices = Indices

        pf.processors = {'.rpy': script.ResourceScript}
        self.root.addHost("my.com", pf)
        self.root.addHost("www.my.com", pf)
        self.root.addHost("my.org", pf)
        self.root.addHost("www.my.org", pf)
        self.root.addHost("my.net", pf)
        self.root.addHost("www.my.net", pf)

        ob = static.File(other)
        ob.indices = Indices
        ob.processors = {".rpy":script.ResourceScript}
        self.root.addHost("other.com", ob)
        self.root.addHost("www.other.com", ob)
        self.Application = app.Application("web")

    def SvcStop (self):

    def SvcDoRun (self):
        we.WaitForSingleObject(self.hWaitStop, we.INFINITE)
        self.Application.listenTCP(80, server.Site(self.root))

if __name__ == "__main__":

domains have been changed to protect the innocent.

"You can have peace. Or you can have freedom. Don't ever count on having
both at once." - Lazarus Long

Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.548 / Virus Database: 341 - Release Date: 12/5/2003

More information about the Twisted-Python mailing list