[Twisted-Python] How to call remote server method to read a file on the server machine useing perspective broker ?
yangyouxiu
yangyouxiu at gmail.com
Tue Nov 19 23:42:09 MST 2013
Hi, all!
I'm trying to read a file on the server with pb, and got an error. Following is my code, what's the problem?
***********************pb1server.py
#!/usr/bin/env python
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
from twisted.spread import pb
class Two(pb.Referenceable):
def remote_three(self, arg):
print "Two.three was given", arg
f=open('/home/gddw/Desktop/test','wr')
content = f.readline()
print content
class One(pb.Root):
def remote_getTwo(self):
two = Two()
print "returning a Two called", two
return two
from twisted.internet import reactor
reactor.listenTCP(8800, pb.PBServerFactory(One()))
reactor.run()
*************************pb1client.py
#!/usr/bin/env python
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
from twisted.spread import pb
from twisted.internet import reactor
def main():
factory = pb.PBClientFactory()
reactor.connectTCP("localhost", 8800, factory)
def1 = factory.getRootObject()
def1.addCallbacks(got_obj1, err_obj1)
reactor.run()
def err_obj1(reason):
print "error getting first object", reason
reactor.stop()
def got_obj1(obj1):
print "got first object:", obj1
print "asking it to getTwo"
def2 = obj1.callRemote("getTwo")
def2.addCallbacks(got_obj2)
def got_obj2(obj2):
print "got second object:", obj2
print "telling it to do three(12)"
obj2.callRemote("three", 12)
main()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20131120/4c7d7fc8/attachment.html>
More information about the Twisted-Python
mailing list