1
# Copyright (c) 2009 Twisted Matrix Laboratories.
2
# See LICENSE for details.
4
from twisted.conch.telnet import TelnetTransport, TelnetProtocol
5
from twisted.internet.protocol import ServerFactory
6
from twisted.application.internet import TCPServer
7
from twisted.application.service import Application
9
class TelnetEcho(TelnetProtocol):
10
def enableRemote(self, option):
11
self.transport.write("You tried to enable %r (I rejected it)\r\n" % (option,))
15
def disableRemote(self, option):
16
self.transport.write("You disabled %r\r\n" % (option,))
19
def enableLocal(self, option):
20
self.transport.write("You tried to make me enable %r (I rejected it)\r\n" % (option,))
24
def disableLocal(self, option):
25
self.transport.write("You asked me to disable %r\r\n" % (option,))
28
def dataReceived(self, data):
29
self.transport.write("I received %r from you\r\n" % (data,))
32
factory = ServerFactory()
33
factory.protocol = lambda: TelnetTransport(TelnetEcho)
34
service = TCPServer(8023, factory)
36
application = Application("Telnet Echo Server")
37
service.setServiceParent(application)