~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to doc/examples/simpleserv.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2004-06-21 22:01:11 UTC
  • mto: (2.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040621220111-vkf909euqnyrp3nr
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# License along with this library; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
from twisted.protocols.protocol import Protocol, Factory
19
 
 
20
 
### Protocol Implementation
21
 
 
22
 
# This is just about the simplest possible protocol
23
 
 
24
 
class Echo(Protocol):
 
18
from twisted.internet import reactor, protocol
 
19
 
 
20
 
 
21
class Echo(protocol.Protocol):
 
22
    """This is just about the simplest possible protocol"""
 
23
    
25
24
    def dataReceived(self, data):
26
25
        "As soon as any data is received, write it back."
27
26
        self.transport.write(data)
28
27
 
29
28
 
30
 
# this runs the protocol on port 8000
31
29
def main():
32
 
    from twisted.internet.app import Application
33
 
    factory = Factory()
 
30
    """This runs the protocol on port 8000"""
 
31
    factory = protocol.ServerFactory()
34
32
    factory.protocol = Echo
35
 
    app = Application("echo")
36
 
    app.listenTCP(8000,factory)
37
 
    app.run(save=0)
 
33
    reactor.listenTCP(8000,factory)
 
34
    reactor.run()
38
35
 
39
36
# this only runs if the module was *not* imported
40
37
if __name__ == '__main__':