Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / conch / examples / telnet_echo.tac
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Simple echo server that echoes back client input.
6
7 You can run this .tac file directly with:
8     twistd -ny telnet_echo.tac
9
10 This demo sets up a listening port on 6023 which accepts telnet connections.
11 No login for the telnet server is required.
12 """
13
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
18
19 class TelnetEcho(TelnetProtocol):
20     def enableRemote(self, option):
21         self.transport.write("You tried to enable %r (I rejected it)\r\n" % (option,))
22         return False
23
24
25     def disableRemote(self, option):
26         self.transport.write("You disabled %r\r\n" % (option,))
27
28
29     def enableLocal(self, option):
30         self.transport.write("You tried to make me enable %r (I rejected it)\r\n" % (option,))
31         return False
32
33
34     def disableLocal(self, option):
35         self.transport.write("You asked me to disable %r\r\n" % (option,))
36
37
38     def dataReceived(self, data):
39         self.transport.write("I received %r from you\r\n" % (data,))
40
41
42 factory = ServerFactory()
43 factory.protocol = lambda: TelnetTransport(TelnetEcho)
44 service = TCPServer(8023, factory)
45
46 application = Application("Telnet Echo Server")
47 service.setServiceParent(application)