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


Python QueuedConnectionManager.getResetConnection方法代码示例

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


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

示例1: TCP

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

#.........这里部分代码省略.........
    def tcpListenerTask(self, task):
        """
        Accept new incoming connection from clients, related to TCP
        """
        # Handle new connection
        if self.tcpListener.newConnectionAvailable():
            rendezvous = PointerToConnection()
            netAddress = NetAddress()
            newConnection = PointerToConnection()
            
            if self.tcpListener.getNewConnection(rendezvous, netAddress, newConnection):
                newConnection = newConnection.p()
                
                # Tell the reader about the new TCP connection
                self.tcpReader.addConnection(newConnection)

                # Handle the connection depending on persistent or not
                if self.core.server.isPersistent:
                    self.core.handleConnection(generateUUID(), newConnection, netAddress)
                else:
                    self.core.createPlayerObject(generateUUID(),newConnection, netAddress)
                    
                print ("Server: New Connection from -", str(netAddress.getIpString()))
            else:
                print ("Server: Connection Failed from -", str(netAddress.getIpString()))    
                    
            
        return Task.cont


    def tcpReaderTask(self, task):
        """
        Handle any data from clients by sending it to the Handlers.
        """
        while 1:
            (datagram, data, opcode) = self.tcpNonBlockingRead(self.tcpReader)
            if opcode is MSG_NONE:
                # Do nothing or use it as some 'keep_alive' thing.
                break
            else:
                # Handle it
                self.core.packetManager.handlePacket(opcode, data, datagram.getAddress())
                
        return Task.cont


    # TCP NonBlockingRead??
    def tcpNonBlockingRead(self, qcr):
        """
        Return a datagram collection and type if data is available on
        the queued connection udpReader
        """
        if self.tcpReader.dataAvailable():
            datagram = NetDatagram()
            if self.tcpReader.getData(datagram):
                data = DatagramIterator(datagram)
                opcode = data.getUint8()

            else:
                data = None
                opcode = MSG_NONE

        else:
            datagram = None
            data = None
            opcode = MSG_NONE

        # Return the datagram to keep a handle on the data
        return (datagram, data, opcode)


    # TCP Disconnection Handler
    def tcpDisconnectionHandler(self, task):
        # Check for resets
        if self.tcpManager.resetConnectionAvailable():
            resetConnection = PointerToConnection()
            self.tcpManager.getResetConnection(resetConnection)
            
            for client in self.core.server.clients:
                if self.core.server.clients[client].connection == resetConnection.p():
                    del self.core.server.clients[client]
                    self.tcpReader.removeConnection(resetConnection.p())
                    print ("Removed Connection:", resetConnection.p())
                    print ('Current Clients:', self.core.server.clients)
                    break

        return Task.cont


    def sendPacket(self, _pkt, _connection):
        self.tcpWriter.send(_pkt, _connection)


    def sendBroadcast(self, _pkt, _skipif=None):
        for client in self.serverManager.clients:
            if _skipif == client:
                pass
            else:
                conn = self.serverManager.clients[client].connection
                self.tcpWriter.send(_pkt, conn)
开发者ID:grimfang,项目名称:grim_net,代码行数:104,代码来源:TCP.py

示例2: SocketTCP

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

#.........这里部分代码省略.........
                # Tell the reader about the new TCP connection
                self.tcpReader.addConnection(newConnection)

                #self.core.createPlayerObject(generateUUID(),newConnection, netAddress)
                    
                print ("Server: " + str(generateUUID), str(netAddress.getIpString()))
            else:
                print ("Server: Connection Failed from -", str(netAddress.getIpString()))    
                    
            
        return Task.cont


    def tcpReaderTask(self, task):
        """
        Handle any data from clients by sending it to the Handlers.
        """
        while 1:
            (datagram, data, opcode) = self.tcpNonBlockingRead(self.tcpReader)
            if opcode is MSG_NONE:
                # Do nothing or use it as some 'keep_alive' thing.
                break
            else:
                # Handle it
                #self.core.packetManager.handlePacket(opcode, data, datagram.getAddress())
                print("Set Packet Handler to handle packets!")
                
        return Task.cont


    # TCP NonBlockingRead??
    def tcpNonBlockingRead(self, qcr):
        """
        Return a datagram collection and type if data is available on
        the queued connection udpReader
        """
        if self.tcpReader.dataAvailable():
            datagram = NetDatagram()
            if self.tcpReader.getData(datagram):
                data = DatagramIterator(datagram)
                opcode = data.getUint8()

            else:
                data = None
                opcode = MSG_NONE

        else:
            datagram = None
            data = None
            opcode = MSG_NONE

        # Return the datagram to keep a handle on the data
        return (datagram, data, opcode)


    # TCP Disconnection Handler
    def tcpDisconnectionHandler(self, task):
        # Check for resets
        if self.tcpManager.resetConnectionAvailable():
            resetConnection = PointerToConnection()
            self.tcpManager.getResetConnection(resetConnection)
            print(str(resetConnection.p()))
            #for client in self.core.server.clients:
            #    if self.core.server.clients[client].connection == resetConnection.p():
            #        del self.core.server.clients[client]
            #        self.tcpReader.removeConnection(resetConnection.p())
            #        print ("Removed Connection:", resetConnection.p())
            #        print ('Current Clients:', self.core.server.clients)
            #        break

        return Task.cont


    def sendPacket(self, _pkt, _connection):
        self.tcpWriter.send(_pkt, _connection)


    def sendBroadcast(self, _pkt, _skipif=None):
        for client in self.serverManager.clients:
            if _skipif == client:
                pass
            else:
                conn = self.serverManager.clients[client].connection
                self.tcpWriter.send(_pkt, conn)

    def addPacketToSendQueue(self, _data):
        # _data should contain packet and connection
        pass

    def addPacketToBroadcastQueue(self, _pkt, _connectionList):
        # _data should contain the pkt data and _connectionList should be the valid connections for that broadcast
        # Could have a grouping system that put clients together and broadcasts go per group
        pass

    def tcpQueuedSendHandlerTask(self, task):
        
        if not self.sendPacketQueue.isEmpty():
            self.addPacketToSendQueue(self.sendPacketQueue.removeFromQue())
        
        return Task.cont
开发者ID:grimfang,项目名称:grim_net,代码行数:104,代码来源:TCP_Socket.py


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