Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / TwistedQuotes / pbquoteclient.py
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