[Twisted-Python] Telnet negotiation with Twisted

Lee Orsino lmorsino at gmail.com
Thu Dec 1 20:00:28 EST 2011


Hi Patrick! Thanks for the suggestion. After I call self.will(LINEMODE), I
get

Failure: twisted.conch.telnet.OptionRefused:
twisted.conch.telnet.OptionRefused:
'"'

So I know at least something is happening. I guess this just became a
Telnet question instead of a twisted question. But I still don't understand
how enableRemote and requestNegotiation are supposed to be used with this.
Anyway, this happens in PuTTY as well as the Windows telnet client. Below
is the code, if it helps, as simple as I could get it. Maybe there is
something obvious that I need to do:



from twisted.internet.protocol import Protocol, Factory
from twisted.conch.telnet import TelnetTransport, TelnetProtocol,
ITelnetProtocol
from twisted.internet import reactor
import sys

class EchoTransport(TelnetTransport):
def __init__(self, protocolFactory=None, *a, **kw):
TelnetTransport.__init__(self)
if protocolFactory is not None:
self.protocolFactory = protocolFactory
self.protocolArgs = a
self.protocolKwArgs = kw

def connectionMade(self):
TelnetTransport.connectionMade(self)
print ("connection made")

def connectionLost(self, reason):
print ("connection lost")
reactor.stop()
 def applicationDataReceived(self, bytes):
TelnetTransport.applicationDataReceived(self, bytes)
bytes = bytes.strip()
 if (bytes == 'b'):
self.will(chr(34)) # Error here
 if (bytes == 'x'):
self.transport.write("goodbye")
TelnetTransport.loseConnection(self)

def main():
    f = Factory()
    f.protocol = lambda: EchoTransport(TelnetProtocol)
    reactor.listenTCP(8023, f)
    reactor.run()


if __name__ == '__main__':
    main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20111201/fd4caade/attachment-0001.htm 


More information about the Twisted-Python mailing list