title: twisted python daemonization and port bindings
body: <p>I am using the following script from the Twisted tutorial (with slight modification):</p>
  
  <pre><code>from twisted.application import internet, service
  from twisted.internet import reactor, protocol, defer
  from twisted.protocols import basic
  from twisted.web import client
  
  class FingerProtocol(basic.LineReceiver):
  
      def lineReceived(self, user):
          d = self.factory.getUser(user)
  
          def onError(err):
              return "Internal server error"
          d.addErrback(onError)
  
          def writeResponse(message):
              self.transport.write(message + "\r\n")
              self.transport.loseConnection()
          d.addCallback(writeResponse)
  
  class FingerFactory(protocol.ServerFactory):
      protocol = FingerProtocol
  
      def __init__(self, prefix):
          self.prefix = prefix
  
      def getUser(self, user):
          return client.getPage(self.prefix + user)
  
  application = service.Application('finger', uid=1, gid=1)
  factory = FingerFactory(prefix="http://livejournal.com/~")
  internet.TCPServer(7979, factory).setServiceParent(
      service.IServiceCollection(application))
  </code></pre>
  
  <p>which I save as <code>finger_daemon.tac</code> and run with</p>
  
  <pre><code>twistd -y finger_daemon.tac \ 
      -l /home/me/twisted/finger.log \
      --pidfile=/home/me/twisted/finger.pid
  </code></pre>
  
  <p>but of course it won't bind to 79, since it's a privileged port. I tried also running with sudo, no difference there. </p>
  
  <p>I then tried changing the <code>TCPServer</code> port to 7979 and then connecting to the daemon once running with </p>
  
  <pre><code>telnet 127.0.0.1 7979
  </code></pre>
  
  <p>and I get <code>Connection Refused</code> error. What's going on here specifically? How is daemonizing supposed to work in Twisted?</p>