dart_mqtt 1.0.2+3 copy "dart_mqtt: ^1.0.2+3" to clipboard
dart_mqtt: ^1.0.2+3 copied to clipboard

outdated

a mqtt library to easy connect via tcp/ssl,dependence xtransport,developing,not stable.

example/README.md

Quickstart Guide #

tcp #

import 'package:dart_mqtt/dart_mqtt.dart';

void main() async {
  var transport = XTransportWsClient.from(
    "broker.emqx.io",
    "/mqtt",
    8083,
    log: true,
    protocols: ["mqtt"], // important
  );
  var cli = MqttClient(transport, log: true, allowReconnect: true)
    ..withKeepalive(10)
    ..withClientID("mqttx_test");
  cli.onMqttConack((msg) {
    // print("onMqttConack: $msg");
    if (msg.returnCode != MqttConnectReturnCode.connectionAccepted) {
      cli.close();
      return;
    }
    cli.reSub();
  });

  cli.onBeforeReconnect(() async {
    print("reconnecting...");
  });
  cli.start();
  cli.subscribe("test/topic", onMessage: (msg) {
    // print(msg);
  });
}

ws #

import 'package:dart_mqtt/dart_mqtt.dart';

void main() async {
  var transport = XTransportWsClient.from(
    "broker.emqx.io",
    "/mqtt",
    8083,
    log: true,
    protocols: ["mqtt"], // important
  );
  var cli = MqttClient(transport, log: true, allowReconnect: true)
    ..withKeepalive(10)
    ..withClientID("mqttx_test");
  cli.onMqttConack((msg) {
    // print("onMqttConack: $msg");
    if (msg.returnCode != MqttConnectReturnCode.connectionAccepted) {
      cli.close();
      return;
    }
    cli.reSub();
  });

  cli.onBeforeReconnect(() async {
    print("reconnecting...");
  });
  cli.start();
  cli.subscribe("test/topic", onMessage: (msg) {
    // print(msg);
  });
}

4
likes
0
pub points
62%
popularity

Publisher

unverified uploader

a mqtt library to easy connect via tcp/ssl,dependence xtransport,developing,not stable.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

xtransport

More

Packages that depend on dart_mqtt