Example #1
0
 def unsuback(self, messageId):
     # LOG.info("Sending unsuback packet")
     header = bytearray()
     varHeader = bytearray()
     header.append(0x0B << 4)
     varHeader.extend(EncodeDecode._encodeValue(messageId))
     header.extend(EncodeDecode._encodeLength(len(varHeader)))
     self.transport.write(header)
     self.transport.write(varHeader)
Example #2
0
 def pubcomp(self, messageId):
     # LOG.warn('Sending pubcomp packet')
     header = bytearray()
     varHeader = bytearray()
     header.append(0x07 << 4)
     varHeader.extend(EncodeDecode._encodeValue(messageId))
     header.extend(EncodeDecode._encodeLength(len(varHeader)))
     self.transport.write(header)
     self.transport.write(varHeader)
Example #3
0
 def _build_fixed_header(self,
                         p_packet_type,
                         p_remaining_length,
                         dup=0,
                         qosLevel=0,
                         retain=0):
     l_header = bytearray()
     l_header.append((p_packet_type & 0x0f) << 4 | (dup & 0x01) << 3
                     | (qosLevel & 0x03) << 1 | (retain & 0x01))
     l_header.extend(EncodeDecode._encodeLength(p_remaining_length))
     return l_header
Example #4
0
 def suback(self, grantedQos, messageId):
     # LOG.info("Sending suback packet")
     header = bytearray()
     varHeader = bytearray()
     payload = bytearray()
     header.append(0x09 << 4)
     varHeader.extend(EncodeDecode._encodeValue(messageId))
     for i in grantedQos:
         payload.append(i)
     header.extend(
         EncodeDecode._encodeLength(len(varHeader) + len(payload)))
     self.transport.write(header)
     self.transport.write(varHeader)
     self.transport.write(payload)
Example #5
0
 def unsubscribe(self, topic, messageId=None):
     # LOG.info("Sending unsubscribe packet")
     header = bytearray()
     varHeader = bytearray()
     payload = bytearray()
     header.append(0x0A << 4 | 0x01 << 1)
     if messageId is not None:
         varHeader.extend(EncodeDecode._encodeValue(self.messageID))
     else:
         varHeader.extend(
             EncodeDecode._encodeValue(random.randint(1, 0xFFFF)))
     payload.extend(EncodeDecode._encodeString(topic))
     header.extend(
         EncodeDecode._encodeLength(len(payload) + len(varHeader)))
     self.transport.write(header)
     self.transport.write(varHeader)
     self.transport.write(payload)
Example #6
0
 def disconnect(self):
     LOG.info("Sending disconnect packet")
     header = bytearray()
     header.append(0x0E << 4)
     header.extend(EncodeDecode._encodeLength(0))
     self.transport.write(header)
Example #7
0
 def pingresp(self):
     LOG.warn('Got ping ack packet')
     header = bytearray()
     header.append(0x0D << 4)
     header.extend(EncodeDecode._encodeLength(0))
     self.transport.write(header)