[Twisted-Python] Telnet server example?
seamonkeys at gmail.com
Wed Aug 11 00:55:08 MDT 2004
Thanks for the example. Just a couple of quick questions if you don't mind.
1) Does this create a telnetd daemon? The checkUserAndPass() method
seems like it checks with the /etc/passwd file to enable a user to
logon. Since I don't have access to my Unix box tonite I can't check
this myself. Please correct me if I'm mistaken.
2) What does defer do exactly?
3) Say I'm writing a program that takes connections via Telnet, like a
chat server. Would using Twisted's Telnet class be the best way to
accomplish this? Or should I just write my own via the more low-level
On Tue, 10 Aug 2004 20:17:39 +0200, Eugene Coetzee
<projects at reedflute.com> wrote:
> Britt Green wrote:
> >So I got my Echo server working...kind of. There were some issues with
> >Putty in Telnet versus Raw Mode, but that's a posting for elsewhere.
> >Anyways, rather than re-invent the wheel I'd like to take advantage of
> >Twisted's Telnet classes. Unfortunately I've not been able to find any
> >examples of a server that uses Twisted's Telnet. I've tried writing my
> >own code but I've not had any luck getting it to work.
> >Therefore...would anyone mind showing me a minimal example of a server
> >that uses the Telnet library?
> >Many thanks,
> >Twisted-Python mailing list
> >Twisted-Python at twistedmatrix.com
> Excuse the mess:
> from twisted.protocols.telnet import *
> from twisted.application import service,internet
> from twisted.internet import protocol,defer
> class TelnetProtocol(Telnet):
> def connectionMade(self):
> print "TelnetProtocol.connectionMade"
> def telnet_Password(self, paswd):
> """I accept a password as an argument, and check it with the
> checkUserAndPass method. If the login is successful, I call
> # checked = self.checkUserAndPass(self.username, paswd)
> # return "Done"
> #if not checked:
> # return "Done"
> return "Command"
> def dataReceived(self,data):
> print "TelnetProtocol.dataReceived"
> print data
> class TelnetFactory(protocol.ServerFactory):
> protocol = TelnetProtocol
> def __init__(self, **kwargs): self.users = kwargs
> def getUser(self, user):
> print "TelnetFactory.getUser"
> print user
> return defer.succeed(self.users.get(user, "No such user"))
> factory = TelnetFactory()
> internet.TCPServer(1021, factory).setServiceParent(
> Do not trust this code - it will open a telnet session without any user
> authentication - you have to play around a little with the class as
> documented at :
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
More information about the Twisted-Python