<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<STYLE>
BLOCKQUOTE {
MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em; MARGIN-TOP: 0px
}
OL {
MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
UL {
MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
P {
MARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
BODY {
FONT-SIZE: 10.5pt; FONT-FAMILY: ΢ÈíÑźÚ; COLOR: #000000; LINE-HEIGHT: 1.5
}
</STYLE>
<META name=GENERATOR content="MSHTML 10.00.9200.16736"></HEAD>
<BODY style="MARGIN: 10px">
<DIV>Hi, all!</DIV>
<DIV style="TEXT-INDENT: 2em">I'm trying to read a file on the server with pb,
and got an error. Following is my code, what's the problem?</DIV>
<DIV style="TEXT-INDENT: 2em">
<DIV> </DIV>
<DIV>***********************pb1server.py</DIV>
<DIV>#!/usr/bin/env python</DIV>
<DIV> </DIV>
<DIV># Copyright (c) Twisted Matrix Laboratories.</DIV>
<DIV># See LICENSE for details.</DIV>
<DIV> </DIV>
<DIV>from twisted.spread import pb</DIV>
<DIV> </DIV>
<DIV>class Two(pb.Referenceable):</DIV>
<DIV> def remote_three(self, arg):</DIV>
<DIV> print "Two.three was given",
arg</DIV>
<DIV>
f=open('/home/gddw/Desktop/test','wr')</DIV>
<DIV> content = f.readline()</DIV>
<DIV> print content</DIV>
<DIV>class One(pb.Root):</DIV>
<DIV> def remote_getTwo(self):</DIV>
<DIV> two = Two()</DIV>
<DIV> print "returning a Two called",
two</DIV>
<DIV> return two</DIV>
<DIV> </DIV>
<DIV>from twisted.internet import reactor</DIV>
<DIV>reactor.listenTCP(8800, pb.PBServerFactory(One()))</DIV>
<DIV>reactor.run()</DIV>
<DIV>*************************pb1client.py</DIV>
<DIV>
<DIV>#!/usr/bin/env python</DIV>
<DIV> </DIV>
<DIV># Copyright (c) Twisted Matrix Laboratories.</DIV>
<DIV># See LICENSE for details.</DIV>
<DIV> </DIV>
<DIV>from twisted.spread import pb</DIV>
<DIV>from twisted.internet import reactor</DIV>
<DIV> </DIV>
<DIV>def main():</DIV>
<DIV> factory = pb.PBClientFactory()</DIV>
<DIV> reactor.connectTCP("localhost", 8800, factory)</DIV>
<DIV> def1 = factory.getRootObject()</DIV>
<DIV> def1.addCallbacks(got_obj1, err_obj1)</DIV>
<DIV> reactor.run()</DIV>
<DIV> </DIV>
<DIV>def err_obj1(reason):</DIV>
<DIV> print "error getting first object", reason</DIV>
<DIV> reactor.stop()</DIV>
<DIV> </DIV>
<DIV>def got_obj1(obj1):</DIV>
<DIV> print "got first object:", obj1</DIV>
<DIV> print "asking it to getTwo"</DIV>
<DIV> def2 = obj1.callRemote("getTwo")</DIV>
<DIV> def2.addCallbacks(got_obj2)</DIV>
<DIV> </DIV>
<DIV>def got_obj2(obj2):</DIV>
<DIV> print "got second object:", obj2</DIV>
<DIV> print "telling it to do three(12)"</DIV>
<DIV> obj2.callRemote("three", 12)</DIV>
<DIV>main()</DIV></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV></DIV></BODY></HTML>