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