Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

package com.codename1.io.mqtt

A small MQTT 3.1.1 client.

MqttClient connects to a broker over plain TCP (tcp://) or over a WebSocket with the mqtt subprotocol (ws:// and wss://, which is how TLS is reached: the TCP transport has no TLS), publishes and subscribes at QoS 0 and QoS 1, and delivers every callback on the Codename One EDT.

MqttCodec and MqttPacket are the transport independent packet layer and work on plain streams. QoS 2 is not implemented: a client never asks a broker for it, and a packet that needs it is a protocol error.

MqttOptions o = new MqttOptions("tcp://broker.example.com:1883", "my-client");
MqttClient c = new MqttClient();
c.connect(o, new MqttListener() {
    public void connected() { c.subscribe("sensors/#", 1); }
    public void messageArrived(String topic, byte[] payload, boolean retained) { }
    public void connectionLost(String reason) { }
});

Types

class MqttClientAn MQTT 3.1.1 client for QoS 0 and QoS 1.
class MqttCodecEncodes and decodes MQTT 3.1.1 control packets on plain streams, so it is independent of the transport.
class MqttExceptionA malformed, oversized or unsupported MQTT packet, or an MQTT protocol violation by the peer.
interface MqttListenerReceives the life cycle and the messages of an MqttClient.
interface MqttMessageListenerReceives the messages of one subscription made with MqttClient.subscribe(String, int, MqttMessageListener).
class MqttOptionsEverything an MqttClient needs to open and identify a connection.
class MqttPacketOne MQTT 3.1.1 control packet as a value.
class MqttTopicTopic names and topic filters: validation and the + / # matching rules of MQTT 3.1.1 section 4.7.