Class MqttPacket

java.lang.Object
com.codename1.io.mqtt.MqttPacket

public final class MqttPacket extends Object
One MQTT 3.1.1 control packet as a value. Build one with the static factories and give it to MqttCodec.write(MqttPacket, java.io.OutputStream); MqttCodec.read(java.io.InputStream, int) returns one. Only the accessors that belong to the packet's getType() carry meaning.
  • Field Details

  • Method Details

    • connect

      public static MqttPacket connect(MqttOptions o)
      Builds a CONNECT packet from the options.
    • connack

      public static MqttPacket connack(boolean sessionPresent, int returnCode)
      Builds a CONNACK packet.
    • publish

      public static MqttPacket publish(String topic, byte[] payload, int qos, boolean retain, boolean dup, int packetId)

      Builds a PUBLISH packet.

      Parameters
      • topic: the topic name

      • payload: the body

      • qos: 0 or 1

      • retain: the retain flag

      • dup: the DUP flag, set on a re-delivery

      • packetId: 1 to 65535 for QoS 1, ignored for QoS 0

    • puback

      public static MqttPacket puback(int packetId)
      Builds a PUBACK packet.
    • subscribe

      public static MqttPacket subscribe(int packetId, String[] filters, int[] qos)
      Builds a SUBSCRIBE packet with parallel arrays of filters and requested QoS.
    • suback

      public static MqttPacket suback(int packetId, int[] returnCodes)
      Builds a SUBACK packet; each code is the granted QoS or 0x80 for failure.
    • unsubscribe

      public static MqttPacket unsubscribe(int packetId, String[] filters)
      Builds an UNSUBSCRIBE packet.
    • unsuback

      public static MqttPacket unsuback(int packetId)
      Builds an UNSUBACK packet.
    • pingreq

      public static MqttPacket pingreq()
      Builds a PINGREQ packet.
    • pingresp

      public static MqttPacket pingresp()
      Builds a PINGRESP packet.
    • disconnect

      public static MqttPacket disconnect()
      Builds a DISCONNECT packet.
    • getType

      public int getType()
      The packet type, one of the constants of this class.
    • getPacketId

      public int getPacketId()
      The packet identifier of PUBLISH (QoS 1), PUBACK, SUBSCRIBE, SUBACK, UNSUBSCRIBE and UNSUBACK.
    • getTopic

      public String getTopic()
      The topic name of a PUBLISH.
    • getPayload

      public byte[] getPayload()
      The body of a PUBLISH.
    • getQos

      public int getQos()
      The QoS of a PUBLISH.
    • isRetain

      public boolean isRetain()
      The retain flag of a PUBLISH.
    • isDup

      public boolean isDup()
      The DUP flag of a PUBLISH.
    • setDup

      public void setDup(boolean dup)
      Sets the DUP flag, used when a PUBLISH is sent again.
    • isSessionPresent

      public boolean isSessionPresent()
      The session present flag of a CONNACK.
    • getReturnCode

      public int getReturnCode()
      The return code of a CONNACK (0 accepted, 1 to 5 refused).
    • getFilters

      public String[] getFilters()
      The topic filters of a SUBSCRIBE or UNSUBSCRIBE.
    • getQosList

      public int[] getQosList()
      The requested QoS list of a SUBSCRIBE, or the return codes of a SUBACK.
    • getClientId

      public String getClientId()
      The client identifier of a CONNECT.
    • isCleanSession

      public boolean isCleanSession()
      The clean session flag of a CONNECT.
    • getKeepAlive

      public int getKeepAlive()
      The keep alive, in seconds, of a CONNECT.
    • getUsername

      public String getUsername()
      The user name of a CONNECT, or null.
    • getPassword

      public byte[] getPassword()
      The password of a CONNECT, or null.
    • getWillTopic

      public String getWillTopic()
      The will topic of a CONNECT, or null.
    • getWillPayload

      public byte[] getWillPayload()
      The will payload of a CONNECT, or null.
    • getWillQos

      public int getWillQos()
      The will QoS of a CONNECT.
    • isWillRetain

      public boolean isWillRetain()
      The will retain flag of a CONNECT.