Skip to content

MQTTClient

Represents an MQTT client, providing capabilities to connect to MQTT brokers, send and receive messages, and handle various MQTT events. This class is the central component for managing MQTT communications in an MQTT capable application.

Fields:

ConnectionOptions Options

Connection related options.

OnConnectedDelegate OnConnected

Called when the client successfully connected to the broker.

OnServerConnectAckMessageDelegate OnServerConnectAckMessage

Called when the broker acknowledged the client's connect packet.

OnApplicationMessageDelegate OnApplicationMessage

Called for every application message sent by the broker.

OnAuthenticationMessageDelegate OnAuthenticationMessage

Called when an authentication packet is received from the broker as part of the extended authentication process.

OnErrorDelegate OnError

Called when an unexpected, unrecoverable error happens. After this event an OnDisconnect event is called too.

OnDisconnectDelegate OnDisconnect

Called after the client disconnects from the broker.

OnStateChangedDelegate OnStateChanged

Called for every internal state change of the client.

ClientStates State

Current state of the client. State changed events are emitted through the OnStateChanged event.

NegotiatedOptions NegotiatedOptions

Options negotiated with the broker.

Session Session

Session instance to persist QoS data.

List<Subscription> Subscriptions

Get all the Subscriptions associated with the MQTT session.
This list will include all the pending subscriptions too (pending for subscribing or unsubscribing).

LoggingContext Context

Context of the MQTTClient and all child instances (like its transport, etc.) that can produce log outputs.

Methods:

Void BeginPacketBuffer()

With the use of BeginPacketBuffer and EndPacketBuffer sent messages can be buffered and sent in less network packets. It supports nested Begin-EndPacketBuffer calls.
Instead of using BeginPacketBuffer and EndPacketBuffer directly, use the PacketBufferHelper instead!

Void EndPacketBuffer()

Call this after a BeginPacketBuffer.
Instead of using BeginPacketBuffer and EndPacketBuffer directly, use the PacketBufferHelper instead!

ConnectPacketBuilder CreateConnectPacketBuilder()

Creates and returns with a ConnectPacketBuilder instance.

Void BeginConnect(ConnectPacketBuilderDelegate, CancellationToken)

Starts the connection process to the broker. It's a non-blocking method. ConnectPacketBuilderCallback is a function that will be called after a successfully transport connection to negotiate protocol details.

Task<MQTTClient> ConnectAsync(ConnectPacketBuilderDelegate, CancellationToken)

Starts connecting to the broker.

DisconnectPacketBuilder CreateDisconnectPacketBuilder()

Creates and returns with a DisconnectPacketBuilder instance.

SubscribePacketBuilder CreateSubscriptionBuilder(String)

Creates and returns with a SubscribePacketBuilder.

BulkSubscribePacketBuilder CreateBulkSubscriptionBuilder()

Creates and returns with a BulkSubscribePacketBuilder instance.

UnsubscribePacketBuilder CreateUnsubscribePacketBuilder(String)

Creates and returns with an UnsubscribePacketBuilder instance.

BulkUnsubscribePacketBuilder CreateBulkUnsubscribePacketBuilder()

Creates and returns with a BulkUnsubscribePacketBuilder instance.

Void AddTopicAlias(String)

Adds a new topic alias.

ApplicationMessagePacketBuilder CreateApplicationMessageBuilder(String)

Creates and returns with an ApplicationMessagePacketBuilder instance.

AuthenticationPacketBuilder CreateAuthenticationPacketBuilder()

Creates and returns with an AuthenticationPacketBuilder instance.

Comments