[Twisted-Python] help! - listenTCP failing

David McNab david at rebirthing.co.nz
Tue Mar 25 23:32:11 EST 2003


Hi,

I'm building an app that will need the ability to start and stop
protocol servers dynamically.

As part of figuring this out, I've added an ApplicationService to the
app, and within ApplicationService.startService(), I'm calling
self.get_application.listenTCP(portnum, myprotocol).

This is having no visible effect, since the port is not getting opened.

I tried, within startService(), calling reactor.listenTCP() instead.
This starts up the protocol and opens the port just fine, but when I
later call app.unlistenTCP(port) to shut down the protocol, I get the
exception (see below).

What am I doing wrong?
What's the best and simplest way to dynamically start and stop server
protocols at runtime()?

Thanks in advance
David

Traceback (most recent call last):
  File "/usr/lib/python2.2/site-packages/twisted/internet/app.py", line
744, in run
    main.run(installSignalHandlers=installSignalHandlers)
  File "/usr/lib/python2.2/site-packages/twisted/internet/main.py", line
106, in run
    _getReactor().run()
  File "/usr/lib/python2.2/site-packages/twisted/internet/default.py",
line 113, in run
    self.mainLoop()
  File "/usr/lib/python2.2/site-packages/twisted/internet/default.py",
line 124, in mainLoop
    self.doIteration(t)
--- <exception caught here> ---
  File "/usr/lib/python2.2/site-packages/twisted/internet/default.py",
line 450, in doSelect
    why = getattr(selectable, method)()
  File "/usr/lib/python2.2/site-packages/twisted/internet/tcp.py", line
105, in doRead
    return self.protocol.dataReceived(data)
  File "/usr/lib/python2.2/site-packages/twisted/protocols/telnet.py",
line 314, in dataReceived
    why = self.processChunk(c)
  File "/usr/lib/python2.2/site-packages/twisted/protocols/telnet.py",
line 261, in processChunk
    self.processLine(buf)
  File "/usr/lib/python2.2/site-packages/twisted/protocols/telnet.py",
line 221, in processLine
    self.mode = getattr(self, "telnet_"+self.mode)(line)
  File "/usr/lib/python2.2/site-packages/twisted/protocols/telnet.py",
line 237, in telnet_Password
    if not self.checkUserAndPass(self.username, paswd):
  File "mytelnetd.py", line 34, in checkUserAndPass
    self.factory.appl.killTelnet()
  File "mytelnetd.py", line 61, in killTelnet
    self.unlistenTCP(2000)
  File "/usr/lib/python2.2/site-packages/twisted/internet/app.py", line
444, in unlistenTCP
    if self._listenerDict.has_key((port_, interface_)):
exceptions.UnboundLocalError: local variable 'port_' referenced before
assignment
 






More information about the Twisted-Python mailing list