サーバーがツイストのパースペクティブ ブローカーでリモート リクエストを行っているクライアントを認識できるようにする方法を理解しようとしています。私はtwisted.spread.pb.Viewable
これを使用することになっていると思いますが、Viewable のメソッドでパースペクティブ引数を試してみると、view_*
None です。
私はこのサーバーを運営しています
import twisted.spread.pb as pb
import twisted.internet.reactor as reactor
class Server(pb.Root):
def __init__(self):
self.v = MyViewable()
def remote_getViewable(self):
return self.v
class MyViewable(pb.Viewable):
def view_foo(self, perspective):
print ("Perspective %s"%perspective)
if __name__ == "__main__":
reactor.listenTCP(54321, pb.PBServerFactory(Server()))
print("Starting reactor")
reactor.run()
そしてこのクライアント
import twisted.spread.pb as pb
import twisted.internet.reactor as reactor
from twisted.internet.defer import inlineCallbacks
@inlineCallbacks
def gotRoot(root):
v1 = yield root.callRemote("getViewable")
v2 = yield root.callRemote("getViewable")
print(v1)
print(v2)
yield v1.callRemote("foo")
yield v2.callRemote("foo")
factory = pb.PBClientFactory()
reactor.connectTCP("localhost", 54321, factory)
d = factory.getRootObject()
d.addCallback(gotRoot)
reactor.run()
サーバーからの出力は
Starting reactor
Perspective None
Perspective None
パースペクティブ引数が None なのはなぜですか?