Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / pb / pb2client.py
1 #!/usr/bin/env python
2
3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
5
6 from twisted.spread import pb
7 from twisted.internet import reactor
8
9 def main():
10     foo = Foo()
11     factory = pb.PBClientFactory()
12     reactor.connectTCP("localhost", 8800, factory)
13     factory.getRootObject().addCallback(foo.step1)
14     reactor.run()
15
16 # keeping globals around is starting to get ugly, so we use a simple class
17 # instead. Instead of hooking one function to the next, we hook one method
18 # to the next.
19
20 class Foo:
21     def __init__(self):
22         self.oneRef = None
23
24     def step1(self, obj):
25         print "got one object:", obj
26         self.oneRef = obj
27         print "asking it to getTwo"
28         self.oneRef.callRemote("getTwo").addCallback(self.step2)
29
30     def step2(self, two):
31         print "got two object:", two
32         print "giving it back to one"
33         print "one is", self.oneRef
34         self.oneRef.callRemote("checkTwo", two)
35
36 main()