Outils pour utilisateurs

Outils du site


using_perspective_broker

Ceci est une ancienne révision du document !


Table des matières

Using Perspective Broker

Niveau Pro et intergalactique !

Traduction Google de Using Perspective Broker améliorée par un humain ayant fait intergalactique en 1ère langue !

Des exemples

Bon là, je ne comprends pas, c'est de l'intergalactique!

Exemple 1

pb1client.py
#!/usr/bin/env python3
 
# 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()
pb1server.py
#!/usr/bin/env python3
 
# 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)
 
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()
Lancement du serveur $ python3 pb1server.py 
returning a Two called <__main__.Two object at 0x7fd4aacfb128>
Two.three was given 12
 
Lancement du client $ python3 pb1client.py 
got first object: <twisted.spread.pb.RemoteReference object at 0x7f00e4c76a90>
asking it to getTwo
got second object: <twisted.spread.pb.RemoteReference object at 0x7f00e4c76b00>
telling it to do three(12)
using_perspective_broker.1669657705.txt.gz · Dernière modification : de serge