[Twisted-Python] RE: [Python-Twisted] How to write a simple telnet client?

Jp Calderone exarkun at divmod.com
Fri Sep 23 15:38:59 EDT 2005

On Fri, 23 Sep 2005 19:38:11 +0200, henning.ramm at mediapro-gmbh.de wrote:
>>Please look at my posts from 11.08.2005 - What is wrong with this
>>instance (topic). I have send there a code of my telnet client. I don't
>>remember what was wrong, but i solve most of problems, so if
>>you had any
>>questions e-mail me. I think that my code is what You need. This is a
>>very simple client and i have developed him.
>I played around with your code at http://twistedmatrix.com/pipermail/twisted-python/2005-August/011115.html, even if I don't understand polish. ;-)
>I didn't expect that one must handle control codes (your function reponseFunct), I expected the protocol to handle that for me, but anyway, that was no problem (i.e. you solved it before). And with your code I could even switch off the echo (your next thread).

You don't actually have to do this.  You can implement iac_DO, iac_DONT, iac_WILL, and iac_WONT to handle feature negotiation.

You can also use twisted.conch.telnet, which presents a slightly more complete API for feature negotiation.

>What I don't understand is how to 'inject' some commands and collect their result.
>What you tried in your "command" function in __main__ can't work, because the protocol has no transport.
>I don't understand how to get at the Factory's actual protocol instance and its transport.

Factory's don't have protocol instances, in general.  A factory is responsible for creating between zero and an unlimited number of instances of a protocol, as they are demanded by established connections.

Protocol.connectionMade is provided as a hook for application-level logic.  You may want to send your commands from that method.  When it is invoked, you will have a transport.


More information about the Twisted-Python mailing list