Debian Codegraph @

docs/core/examples/simpleserv.py

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