⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metaclient.py

📁 大型多人在线游戏开发,该书光盘上附带的源码
💻 PY
字号:
from twisted.spread.pb import authIdentity, getObjectAt, portnofrom twisted.spread.flavors import Referenceablefrom twisted.internet import reactorfrom twisted.internet.defer import DeferredListclass BugClient(Referenceable):    def gotPerspective(self, pref):        print 'got bug'        pref.callRemote("goToPsychologist","The Tick").addCallback(self.notify)        pref.callRemote("psychoanalyze").addCallback(self.notify)    def notify(self, text):        print 'bug:', text    def remote_healed(self, healedMessage):        print 'Healed:', healedMessageclass CellClient(Referenceable):    def gotPerspective(self, pref):        print 'got cell'        # pref.callRemote()    def remote_connected(self):        print 'Cell Connected'    def remote_hear(self, text):        print 'Phone:', text    def remote_ring(self, callerID):        print "Your phone is ringing.  It's a call from", callerIDbugClient = BugClient()phoneClient = CellClient()# Log-In Informationusername = "bob"password = "bobpass"bugName = "franz"phoneNumber = "222-303-8485"    # A little magic to get us connected...getObjectAt("localhost", portno).addCallback(    # challenge-response authentication    lambda r: authIdentity(r, username, password)).addCallback(    # connecting to each perspective with 'attach' method of remote identity    lambda i: DeferredList([    i.callRemote("attach", "metamorph", bugName, bugClient),    i.callRemote("attach", "cellphone", phoneNumber, phoneClient)])    # connecting perspectives to client-side objects    ).addCallback(lambda l: (bugClient.gotPerspective(l[0][1]),                             phoneClient.gotPerspective(l[1][1])))reactor.callLater(5, reactor.stop) # In five seconds, log out.reactor.run() # Start the main loop.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -