Rust

client

Module

An MQTT client connection: sends encoded packets and receives whole ones.

Contents

use utopia_mqtt::Client;
Rust
pub struct Client

A connection to an MQTT broker over TCP (mqtt://) or TLS (mqtts://), sending packets the caller encodes (see crate::spec) and receiving whole packets, framed by their fixed header.

Hooks see the connection's life: on_open once connected, on_receive with each packet, on_close once it ends, and on_error with each failure. A receive hook that fails is reported to the error hook, then the connection closes.

The broker's TLS certificate is not verified, as Swoole's client does not verify it by default (a quirk the compat spec records).

Rust
use utopia_mqtt::client::{Client, Options};

let client = Client::new("mqtts://broker.local", Options::default())?;
assert_eq!((client.host(), client.port(), client.is_tls()), (&b"broker.local"[..], 8883, true));
assert!(!client.is_connected());
assert_eq!(Client::new("mqtt://", Options::default()).unwrap_err().to_string(), "Invalid MQTT URL");
Also implements Debug.
use utopia_mqtt::client::Options;
Rust
pub struct Options

Options of a Client.

Also implements Default.
Rust
pub const TIMED_OUT: i64 = 110

The errno Linux gives a receive that timed out, as Swoole reports it.