(self, data)
数据到达处理
        @param data: str 客户端传送过来的数据
数据到达处理
数据到达处理
def dataReceived(self, data):
        
        '''数据到达处理
        @param data: str 客户端传送过来的数据
        '''
        length = self.factory.dataprotocl.getHeadlength()#获取协议头的长度
        self.buff += data
        while self.buff.__len__() >= length: 
            unpackdata = self.factory.dataprotocl.unpack(self.buff[:length])
            if not unpackdata.get('result'):
                log.msg('illegal data package --')
                self.factory.connmanager.loseConnection(self.transport.sessionno)
                break
            command = unpackdata.get('command')
            rlength = unpackdata.get('length')
            request = self.buff[length:length+rlength]
            if request.__len__()< rlength:
                log.msg('some data lose')
                break
            self.buff = self.buff[length+rlength:]
            response = self.factory.doDataReceived(self,command,request)
            if not response:
                continue
            self.safeToWriteData(response, command)
def dataReceived ( self , data ) : length = self . factory . dataprotocl . getHeadlength ( ) #获取协议头的长度 self . buff += data while self . buff . __len__ ( ) >= length : unpackdata = self . factory . dataprotocl . unpack ( self . buff [ : length ] ) if not unpackdata . get ( 'result' ) : log . msg ( 'illegal data package --' ) self . factory . connmanager . loseConnection ( self . transport . sessionno ) break command = unpackdata . get ( 'command' ) rlength = unpackdata . get ( 'length' ) request = self . buff [ length : length + rlength ] if request . __len__ ( ) < rlength : log . msg ( 'some data lose' ) break self . buff = self . buff [ length + rlength : ] response = self . factory . doDataReceived ( self , command , request ) if not response : continue self . safeToWriteData ( response , command )