1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Simple echo server that echoes back client input.
7 You can run this .tac file directly with:
8 twistd -ny telnet_echo.tac
10 This demo sets up a listening port on 6023 which accepts telnet connections.
11 No login for the telnet server is required.
14 from twisted.conch.telnet import TelnetTransport, TelnetProtocol
15 from twisted.internet.protocol import ServerFactory
16 from twisted.application.internet import TCPServer
17 from twisted.application.service import Application
19 class TelnetEcho(TelnetProtocol):
20 def enableRemote(self, option):
21 self.transport.write("You tried to enable %r (I rejected it)\r\n" % (option,))
25 def disableRemote(self, option):
26 self.transport.write("You disabled %r\r\n" % (option,))
29 def enableLocal(self, option):
30 self.transport.write("You tried to make me enable %r (I rejected it)\r\n" % (option,))
34 def disableLocal(self, option):
35 self.transport.write("You asked me to disable %r\r\n" % (option,))
38 def dataReceived(self, data):
39 self.transport.write("I received %r from you\r\n" % (data,))
42 factory = ServerFactory()
43 factory.protocol = lambda: TelnetTransport(TelnetEcho)
44 service = TCPServer(8023, factory)
46 application = Application("Telnet Echo Server")
47 service.setServiceParent(application)