~divmod-dev/divmod.org/trunk

« back to all changes in this revision

Viewing changes to Epsilon/doc/listings/amp/route_server.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-29 20:33:04 UTC
  • mfrom: (2749.1.1 remove-epsilon-1325289)
  • Revision ID: exarkun@twistedmatrix.com-20140629203304-gdkmbwl1suei4m97
mergeĀ lp:~exarkun/divmod.org/remove-epsilon-1325289

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2008 Divmod.  See LICENSE for details.
2
 
 
3
 
from sys import stdout
4
 
 
5
 
from twisted.python.log import startLogging
6
 
from twisted.protocols.amp import Integer, Command, AMP
7
 
from twisted.internet import reactor
8
 
 
9
 
from route_setup import AMPRouteServerFactory
10
 
 
11
 
 
12
 
class Count(Command):
13
 
    response = [('value', Integer())]
14
 
 
15
 
 
16
 
 
17
 
class Counter(AMP):
18
 
    _valueCounter = 0
19
 
 
20
 
    @Count.responder
21
 
    def count(self):
22
 
        self._valueCounter += 1
23
 
        return {'value': self._valueCounter}
24
 
 
25
 
 
26
 
 
27
 
def main():
28
 
    startLogging(stdout)
29
 
    serverFactory = AMPRouteServerFactory()
30
 
    serverFactory.routeProtocol = Counter
31
 
    reactor.listenTCP(7805, serverFactory)
32
 
    reactor.run()
33
 
 
34
 
 
35
 
 
36
 
if __name__ == '__main__':
37
 
    main()