| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
# Copyright (c) Twisted Matrix Laboratories. |
| 4 |
# See LICENSE for details. |
| 5 |
|
| 6 |
from twisted.internet import reactor |
| 7 |
from twisted.internet.protocol import Factory, Protocol |
| 8 |
|
| 9 |
### Protocol Implementation |
| 10 |
|
| 11 |
# This is just about the simplest possible protocol |
| 12 |
|
| 13 |
|
| 14 |
class Echo(Protocol): |
| 15 |
def dataReceived(self, data): |
| 16 |
""" |
| 17 |
As soon as any data is received, write it back. |
| 18 |
""" |
| 19 |
self.transport.write(data) |
| 20 |
|
| 21 |
|
| 22 |
def main(): |
| 23 |
f = Factory() |
| 24 |
f.protocol = Echo |
| 25 |
reactor.listenTCP(8000, f) |
| 26 |
reactor.run() |
| 27 |
|
| 28 |
|
| 29 |
if __name__ == "__main__": |
| 30 |
main() |