Ticket #4932: echoserv.py

File echoserv.py, 595 bytes (added by detly, 3 years ago)

Echo server

Line 
1#!/usr/bin/env python
2
3# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
4# See LICENSE for details.
5
6from twisted.internet.protocol import Protocol, Factory
7from twisted.internet import reactor
8
9### Protocol Implementation
10
11# This is just about the simplest possible protocol
12class 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
20def main():
21    f = Factory()
22    f.protocol = Echo
23    reactor.listenTCP(31415, f)
24    reactor.run()
25
26if __name__ == '__main__':
27    main()