Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / examples / simpleserv.py
1
2 # Copyright (c) Twisted Matrix Laboratories.
3 # See LICENSE for details.
4
5
6 from twisted.internet import reactor, protocol
7
8
9 class Echo(protocol.Protocol):
10     """This is just about the simplest possible protocol"""
11     
12     def dataReceived(self, data):
13         "As soon as any data is received, write it back."
14         self.transport.write(data)
15
16
17 def main():
18     """This runs the protocol on port 8000"""
19     factory = protocol.ServerFactory()
20     factory.protocol = Echo
21     reactor.listenTCP(8000,factory)
22     reactor.run()
23
24 # this only runs if the module was *not* imported
25 if __name__ == '__main__':
26     main()