Sophie

Sophie

distrib > Mageia > 6 > i586 > media > core-release > by-pkgid > 248e2f92d9b832e75f95c6042e4252e2 > files > 2775

python-twisted-16.3.2-1.mga6.i586.rpm


from sys import stdout
from twisted.python import log
log.discardLogs()
from twisted.internet import reactor
from twisted.spread import pb

def connected(root):
    root.callRemote('nextQuote').addCallbacks(success, failure)

def success(quote):
    stdout.write(quote + "\n")
    reactor.stop()

def failure(error):
    stdout.write("Failed to obtain quote.\n")
    reactor.stop()

factory = pb.PBClientFactory()
reactor.connectTCP(
    "localhost", # host name
    pb.portno, # port number
    factory, # factory
    )



factory.getRootObject().addCallbacks(connected, # when we get the root
                                     failure)   # when we can't

reactor.run() # start the main loop