Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class MqttPacket
- Object
- MqttPacket
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.Fields
public static final int CONNECT = 1 | Packet type CONNECT. |
public static final int CONNACK = 2 | Packet type CONNACK. |
public static final int PUBLISH = 3 | Packet type PUBLISH. |
public static final int PUBACK = 4 | Packet type PUBACK. |
public static final int SUBSCRIBE = 8 | Packet type SUBSCRIBE. |
public static final int SUBACK = 9 | Packet type SUBACK. |
public static final int UNSUBSCRIBE = 10 | Packet type UNSUBSCRIBE. |
public static final int UNSUBACK = 11 | Packet type UNSUBACK. |
public static final int PINGREQ = 12 | Packet type PINGREQ. |
public static final int PINGRESP = 13 | Packet type PINGRESP. |
public static final int DISCONNECT = 14 | Packet type DISCONNECT. |
Methods
Inherited methods
Field details
CONNECT
public static final int CONNECT = 1Packet type CONNECT.
CONNACK
public static final int CONNACK = 2Packet type CONNACK.
PUBLISH
public static final int PUBLISH = 3Packet type PUBLISH.
PUBACK
public static final int PUBACK = 4Packet type PUBACK.
SUBSCRIBE
public static final int SUBSCRIBE = 8Packet type SUBSCRIBE.
SUBACK
public static final int SUBACK = 9Packet type SUBACK.
UNSUBSCRIBE
public static final int UNSUBSCRIBE = 10Packet type UNSUBSCRIBE.
UNSUBACK
public static final int UNSUBACK = 11Packet type UNSUBACK.
PINGREQ
public static final int PINGREQ = 12Packet type PINGREQ.
PINGRESP
public static final int PINGRESP = 13Packet type PINGRESP.
DISCONNECT
public static final int DISCONNECT = 14Packet type DISCONNECT.
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
topicString- the topic name
payloadbyte[]- the body
qosint- 0 or 1
retainboolean- the retain flag
dupboolean- the DUP flag, set on a re-delivery
packetIdint- 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.