Sophie

Sophie

distrib > Mageia > 6 > x86_64 > by-pkgid > 09408f3c1571cbb746da49a1d2f22702 > files > 3031

python-twisted-17.5.0-1.mga6.x86_64.rpm

# test the PB finger on port 8889
# this code is essentially the same as
# the first example in howto/pb-usage

from __future__ import print_function

from twisted.spread import pb
from twisted.internet import reactor, endpoints

def gotObject(object):
    print("got object:", object)
    object.callRemote("getUser","moshez").addCallback(gotData)
# or
#   object.callRemote("getUsers").addCallback(gotData)

def gotData(data):
    print('server sent:', data)
    reactor.stop()

def gotNoObject(reason):
    print("no object:",reason)
    reactor.stop()

factory = pb.PBClientFactory()
clientEndpoint = endpoints.clientFromString("tcp:127.0.0.1:8889")
clientEndpoint.connect(factory)
factory.getRootObject().addCallbacks(gotObject,gotNoObject)
reactor.run()