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


Python QueuedConnectionManager.getData方法代码示例

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


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

示例1: __init__

# 需要导入模块: from panda3d.core import QueuedConnectionManager [as 别名]
# 或者: from panda3d.core.QueuedConnectionManager import getData [as 别名]

#.........这里部分代码省略.........
        self.world = worldMgr.gameWorld

        #self.connection = None

    def startConnection(self):
        """Create a connection with the remote host.

        If a connection can be created, create a task with a sort value of -39
        to read packets from the socket.

        """
        try:

            taskMgr.add(self.updateRoutine, 'updateRoutine-Connection', -39)
            taskMgr.doMethodLater(.5, self.heartBeat, 'heartBeat')

            return True
        except:
            pass

        return False

    def closeConnection(self):
        """Close the current connection with the remote host.

        If an existing connection is found, remove both the Main task, which
        is responsible for the heartbeat, and the Connection task, which is
        responsible for reading packets from the socket, then properly close
        the existing connection.

        """
        if self.connection != None:
            taskMgr.remove('updateRoutine-Main')
            taskMgr.remove('updateRoutine-Connection')
            taskMgr.remove('heartBeat')

            self.cManager.closeConnection(self.connection)
            self.connection = None

    def sendRequest(self, requestCode, args = {}):
        """Prepare a request packet to be sent.

        If the following request code exists, create an instance of this
        specific request using any extra arguments, then properly send it to
        the remote host.

        """
        if self.connection != None:
            request = self.rqTable.get(requestCode)

            if request != None:
                request.set(self.cWriter, self.connection)
                request.send(args)

    def handleResponse(self, responseCode, data):
        """Prepare a response packet to be processed.

        If the following response code exists, create an instance of this
        specific response using its data to be executed.

        """
        response = self.rsTable.get(responseCode)
        #print("Response Recevied: " , responseCode)

        if response != None:
            response.set(self.world, self.worldMgr)
            response.execute(data)

    def heartBeat(self, task):

        if not self.cReader.isConnectionOk(self.connection):
            self.closeConnection()
            self.showDisconnected(0)

            return task.done
        else :
            self.sendRequest(Constants.REQ_HEARTBEAT)
        return task.cont



        return task.again

    def updateRoutine(self, task):
        """A once-per-frame task used to read packets from the socket."""
        while self.cReader.dataAvailable():
            #print"updateRoutine data available"
            # Create a datagram to store all necessary data.
            datagram = NetDatagram()
            # Retrieve the contents of the datagram.
            if self.cReader.getData(datagram):
                # Prepare the datagram to be iterated.
                data = PyDatagramIterator(datagram)
                # Retrieve a "short" that contains the response code.
                responseCode = data.getUint16()
                # Pass into another method to execute the response.
                if responseCode != Constants.MSG_NONE:
                    self.handleResponse(responseCode, data)

        return task.cont
开发者ID:genusgant,项目名称:CS594-ThrottleThunder-GameClient,代码行数:104,代码来源:ConnectionManager.py


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