当前位置: 首页>>代码示例>>Python>>正文


Python Dispatcher.registers方法代码示例

本文整理汇总了Python中dispatcher.Dispatcher.registers方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatcher.registers方法的具体用法?Python Dispatcher.registers怎么用?Python Dispatcher.registers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dispatcher.Dispatcher的用法示例。


在下文中一共展示了Dispatcher.registers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Client

# 需要导入模块: from dispatcher import Dispatcher [as 别名]
# 或者: from dispatcher.Dispatcher import registers [as 别名]
class Client(NetStream, QtCore.QObject):
    def __init__(self, headMode=8, serverIP="127.0.0.1", serverPort=4829, sleepInterval=0.1, parent=None):
        NetStream.__init__(self, headMode)
        QtCore.QObject.__init__(self)
        print "Client Init ", serverIP, serverPort
        self.initData(serverIP, serverPort, sleepInterval, parent)
        self.setup()
        self.parent.parent.connect(self, QtCore.SIGNAL("serverCrashedAlert()"), self.parent.parent.serverCrashedAlert)

    def initData(self, serverIP, serverPort, sleepInterval, parent):
        self.serverIP = serverIP
        self.serverPort = serverPort
        self.sleepInterval = sleepInterval
        self.dispatcher = Dispatcher()
        self.parent = parent
        self.isAlive = True
        self.hasBegan = False

    def killClient(self):
        self.isAlive = False

    def setup(self):
        self.setupDispatcher()
        self.setupClient()

    def setupDispatcher(self):
        self.dispatcher.setParent(self)
        services = {
            1001: LoginService(self.dispatcher),
            1002: HallService(self.dispatcher),
            1003: RoomService(self.dispatcher),
        }
        self.dispatcher.registers(services)

    def setupClient(self):
        print self.serverPort, "\n", self.serverIP
        self.connect(self.serverIP, self.serverPort)
        self.nodelay(0)
        self.nodelay(1)

    def sendToServer(self, serviceID, commandID, data):
        message = {}
        message["create_time"] = time.time()
        message["service_id"] = serviceID
        message["command_id"] = commandID
        message["data"] = data
        try:
            messageString = json.dumps(message)
        except TypeError, e:
            print "Error while dumping json"
            print e
            print message
        print "Sending Messgae:", message
        self.send(messageString)
开发者ID:bookug,项目名称:GoBang,代码行数:56,代码来源:client.py


注:本文中的dispatcher.Dispatcher.registers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。