[Twisted-Python] Telnet negotiation with Twisted

Patrick Mylund Nielsen twisted at patrickmylund.com
Thu Dec 1 19:26:03 EST 2011


Hi Lee,

Does using TelnetTransport 'will' and 'requestNegotation' work? E.g.

self.will(LINEMODE)
self.requestNegotiation(LINEMODE, '')

I'm not completely sure about LINEMODE, but if the client sends back a
DO, you might use something like:

class MyTransport(TelnetTransport):

    def connectionMade(self):
        self.linemode = False
        self.will(LINEMODE)
        TelnetTransport.connectionMade(self)

    def commandReceived(self, command, argument):
        if argument == LINEMODE:
            if command == DO:
                self.requestNegotiation(LINEMODE, '')
                self.linemode = True
            elif command == DONT:
                pass
        else:
            TelnetTransport.commandReceived(self, command, argument)

    def write(self, data):
        if self.linemode:
            # do something special
        else:
            self.transport.write(data)

Best,
Patrick

On Fri, Dec 2, 2011 at 01:12, Lee Orsino <lmorsino at gmail.com> wrote:
> Hi all,
>
> I'm writing a twisted Telnet server and I want a client to be able to
> connect to it through some other interface, such as PuTTY.  I can make the
> connection fine. But one of my requirements is to be able to tell the client
> to switch back and forth between buffered and unbuffered input modes
> depending on the state of the server. (Sometimes, the client should enter
> text, then hit enter to send. Other times, the client should send data
> character-by-character).
>
> I'm new at this, and maybe I'm missing something, but in my TelnetTransport
> object, I do something like this to disable buffering of client data:
>
> self.transport.write(IAC + WILL + LINEMODE)
> self.transport.write(IAC + SB + LINEMODE + MODE + chr(0) + IAC + SE)
>
> Not working though. PuTTY still requires me to hit <enter> after I type.
> I've tried various combinations of the above. I'm sure I'm doing something
> wrong but its just really hard to find an example of this on the net. I'd
> appreciate some advice as to how to proceed, or a simple example if you have
> time...
>
> I'm using the twisted Telnet classes found here:
> http://twistedmatrix.com/trac/browser/tags/releases/twisted-8.2.0/twisted/conch/telnet.py
>
> Thanks!
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>



More information about the Twisted-Python mailing list