[Twisted-Python] How to call remote server method to read a file on the server machine useing perspective broker ?
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()
Did you try reading the error message? I don't think 'wr' is an allowed mode for open()
Thank you very much! You are right. It should be 'r+' mode, ^_^ From: Daniel Sank Date: 2013-11-20 14:59 To: Twisted general discussion Subject: Re: [Twisted-Python] How to call remote server method to read a file on the server machine useing perspective broker ? Did you try reading the error message? I don't think 'wr' is an allowed mode for open() _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (2)
-
Daniel Sank
-
yangyouxiu