~soren/nova/iptables-security-groups

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/howto/listings/TwistedQuotes/pbquoteclient.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
from sys import stdout
 
3
from twisted.python import log
 
4
log.discardLogs()
 
5
from twisted.internet import reactor
 
6
from twisted.spread import pb
 
7
 
 
8
def connected(root):
 
9
    root.callRemote('nextQuote').addCallbacks(success, failure)
 
10
 
 
11
def success(quote):
 
12
    stdout.write(quote + "\n")
 
13
    reactor.stop()
 
14
 
 
15
def failure(error):
 
16
    stdout.write("Failed to obtain quote.\n")
 
17
    reactor.stop()
 
18
 
 
19
factory = pb.PBClientFactory()
 
20
reactor.connectTCP(
 
21
    "localhost", # host name
 
22
    pb.portno, # port number
 
23
    factory, # factory
 
24
    )
 
25
 
 
26
 
 
27
 
 
28
factory.getRootObject().addCallbacks(connected, # when we get the root
 
29
                                     failure)   # when we can't
 
30
 
 
31
reactor.run() # start the main loop
 
32