Exemplo n.º 1
0
 def handlePdu(self):
     if len(self._buffer) < 16:
         log.info('recv data error: {}, length: {}'.format(
             self._buffer, len(self._buffer)))
         return
     pdu = ImPdu()
     try:
         pdu.FromString(self._buffer)
     except Exception:
         log.info('=========> buffer is : [{}]'.format(self._buffer))
         log.info(traceback.format_exc())
     self._buffer = ''
     if pdu.command_id == CID_LOGIN_RES_USERLOGIN:
         self.handleLoginResponse(pdu)
     elif pdu.command_id == CID_BUDDY_LIST_RECENT_CONTACT_SESSION_RESPONSE:
         self.handleRecentContactSessionResponse(pdu)
     elif pdu.command_id == CID_BUDDY_LIST_USER_INFO_RESPONSE:
         self.hanledUserInfo(pdu)
     elif pdu.command_id == CID_MSG_DATA_ACK:
         self.handleSendMsg(pdu)
     elif pdu.command_id == CID_MSG_UNREAD_CNT_RESPONSE:
         self.handleUnreadCnt(pdu)
     elif pdu.command_id == CID_MSG_DATA:
         self.handleMsgData(pdu)
     elif pdu.command_id == CID_MSG_LIST_RESPONSE:
         self.handleListResponse(pdu)
     elif pdu.command_id == CID_OTHER_HEARTBEAT:
         self.handleHeartBeat(pdu)
     elif pdu.command_id == CID_MSG_READ_NOTIFY:
         self.handleReadNotify(pdu)
     else:
         log.info('Invalid command_id: {}'.format(pdu.command_id))
Exemplo n.º 2
0
 def recvData(self):
     pdu = ImPdu()
     try:
         pduheaderbuf = self._socket.recv(16)
     except Exception as e:
         if e.errno == errno.ECONNRESET:
             log.error('receive failed: {}'.format(traceback.format_exc()))
             self._connected = False
     else:
         if len(pduheaderbuf) != 16:
             log.error("read pdu len errror, len: {}".format(
                 len(pduheaderbuf)))
             self._connected = False
             return
         try:
             pdu.FromString(pduheaderbuf)
         except Exception:
             log.error('unpack pdu length error: {}'.format(
                 traceback.format_exc()))
         else:
             buf = self._socket.recv(pdu.length - 16)
             self._buffer = pduheaderbuf
             self._buffer += buf
     self.handlePdu()