from twisted.spread import pb
from twisted.internet import reactor
from twisted.cred import credentials
class Client(pb.Referenceable):
def remote_print(self, message):
print message
def connect(self):
factory = pb.PBClientFactory()
reactor.connectTCP("localhost", 8800, factory)
def1 = factory.login(credentials.UsernamePassword("alice", "1234"),
client=self)
def1.addCallback(self.connected)
reactor.run()
def connected(self, perspective):
print "connected, joining group #lookingForFourth"
d = perspective.callRemote("joinGroup", "#lookingForFourth")
d.addCallback(self.gotGroup)
def gotGroup(self, group):
print "joined group, now sending a message to all members"
d = group.callRemote("send", "You can call me Al.")
d.addCallback(self.shutdown)
def shutdown(self, result):
reactor.stop()
Client().connect()