com.Tivadar.Best.MQTT https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901106 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901108 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901117 Set to true if it's not the first occasion the broker sent this application message. QoS this application message sent with. Set to true if this is a retained application message. The topic's name this application message is publish to. Payload type (binary or text). Expiry interval of the application message. Topic alias index the broker used. Topic name where the publisher waiting for a response to this application message. Arbitrary data sent with the application message. Key-value pairs sent with the application message. Arbitrary value set by the publisher. Payload of the application message. Supported transports that can be used to connect with. Transport over raw TCP. NOT available under WebGL. Transport using WebSocket connections. Available on all supported platforms! Connection related options to pass to the MQTTClient. Simple example on how to create a connection: ConnectionOptions options = new ConnectionOptions { Host = "localhost", Port = 1883, ProtocolVersion = SupportedProtocolVersions.MQTT_3_1_1 }; var client = new MQTTClient(options); Host name or IP address of the broker. Port number where the broker is listening on. Whether to use a secure protocol (TLS over TCP or wss://). Selected transport to connect with. Optional path for websocket, its default is "/mqtt". The protocol version that the plugin has to use to connect with to the server. Builder class to help creating instances. The following example creates a to connect to localhost on port 1883 using the TCP transport and MQTT protocol version v3.1.1. var options = new ConnectionOptionsBuilder() .WithTCP("localhost", 1883) .WithProtocolVersion(SupportedProtocolVersions.MQTT_3_1_1) .Build(); var client = new MQTTClient(options); This is the same as the previous example, but the builder creates the too. var client = new ConnectionOptionsBuilder() .WithTCP("localhost", 1883) .WithProtocolVersion(SupportedProtocolVersions.MQTT_3_1_1) .CreateClient(); Add options for a TCP connection. Add options for a WebSocket connection. When used MQTTClient going to use TLS to secure the communication. Used by the WebSocket transport to connect to the given path. The protocol version that the plugin has to use to connect with to the server. Creates an MQTTClient object with the already set options. Creates the final ConnectionOptions instance. 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. Connection related options. Called when the client successfully connected to the broker. Called when the broker acknowledged the client's connect packet. Called for every application message sent by the broker. Called when an authentication packet is received from the broker as part of the extended authentication process. Called when an unexpected, unrecoverable error happens. After this event an OnDisconnect event is called too. Called after the client disconnects from the broker. Called for every internal state change of the client. Current state of the client. State changed events are emitted through the OnStateChanged event. Options negotiated with the broker. Session instance to persist QoS data. Context of the MQTTClient and all child instances (like its transport, etc.) that can produce log outputs. https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901251 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901151 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901131 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901100 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205 When a Client reconnects with Clean Start set to 0 and a session is present, both the Client and Server MUST resend any unacknowledged PUBLISH packets (where QoS > 0) and PUBREL packets using their original Packet Identifiers. https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901238 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 and directly, use the instead! Call this after a BeginPacketBuffer. Instead of using and directly, use the instead! Creates and returns with a ConnectPacketBuilder instance. 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. Connect without any customization. client.BeginConnect((client, builder) => builder); Starts connecting to the broker. Creates and returns with a DisconnectPacketBuilder instance. Creates and returns with a SubscribePacketBuilder. Creates and returns with a BulkSubscribePacketBuilder instance. Creates and returns with an UnsubscribePacketBuilder instance. Creates and returns with a BulkUnsubscribePacketBuilder instance. Adds a new topic alias. Creates and returns with an ApplicationMessagePacketBuilder instance. Creates and returns with an AuthenticationPacketBuilder instance. Possible states of the MQTTClient. State right after constructing the MQTTClient. Connection process initiated. Transport successfully connected to the broker. Connect packet sent and acknowledgement received. Disconnect process initiated. Client disconnected from the broker. This could be the result either of a graceful termination or an unexpected error. Private class to hold connection related information. These information are needed only while connecting. Builder class to make MQTTClient creation easier. Creates an MQTTClient instance. Options that the client and server must agree on. Values that the client would like to use are the root fields (Client*) and the server's own are in the ServerOptions. Client set keep-alive time in seconds. Maximum Packet Size the Client is willing to accept The Client uses this value to limit the number of QoS 1 and QoS 2 publications that it is willing to process concurrently. There is no mechanism to limit the QoS 0 publications that the Server might try to send. The value of Receive Maximum applies only to the current Network Connection. If the Receive Maximum value is absent then its value defaults to 65,535. It's available only after the State is changed to Connected! Helper class to help safely use MQTTClient's BeginPacketBuffer-EndPacketBuffer pairs in a using. Builder to create an application message. Set the duplicate flag. (Not really used, it's set directly in MessageDeliveryRetry function) Send the packet with a packet ID required for > QoS 0. Build the packet with the given QoS level. Build the packet with the given retain flag. Build the packet with the given topic name. Build the packet with the given payload format indicator. Set the application message's expiry interval (it's in seconds). https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901113 Set the application message's response topic. Optional data sent with the application message. Optional key value pairs that will be sent with the application message. https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901117 Optional Content-Type value to help process the application message's payload. Set the application message's payload. Set the application message's payload. It also sets the payload format indicator to PayloadTypes.UTF8. Begin sending the application message to the broker. Internal struct to aid publish-property building. https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901217 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901161 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901179 TODO: Set the topic the last-will will be published. Binary payload of the last-will. Textual payload of the last-will. It also sets the Payload Format Indicator to UTF8. QoS level of the last-will. Retain flag. Delay before the broker will publish the last-will Type of the payload, binary or textual. TODO: add detailed description In this example the `ConnectPacketBuilderCallback` returns with the builder received as its second parameter without modifying it. In the callback a new `ConnectPacketBuilder` can be created, but it's easier just to use the one already passed in the parameter. var options = new ConnectionOptionsBuilder() .WithTCP("test.mosquitto.org", 1883) .Build(); client = new MQTTClient(options); client.BeginConnect(ConnectPacketBuilderCallback); ConnectPacketBuilder ConnectPacketBuilderCallback(MQTTClient client, ConnectPacketBuilder builder) { return builder; } Add UserName and Password ConnectPacketBuilder ConnectPacketBuilderCallback(MQTTClient client, ConnectPacketBuilder builder) { return builder.WithUserNameAndPassword("username", "password"); } This specifies whether the connection starts a new session or is a continuation of an existing session. When `WithCleanStart` is used, both the broker and client deletes theirs previously stored session data. The client continues to use its client id. Maximum seconds that can be pass between sending two packets to the broker. If no other packets are sent, the plugin will send ping requests to check and keep the connection alive. A last will can be added to the connection. The will message will be published by the broker after the network connection is subsequently closed and either the Will Delay Interval has elapsed or the session ends, unless the will message has been deleted by the broker on receipt of a DISCONNECT packet with Reason Code `NormalDisconnection` or a new network connection for the ClientID is opened before the Will Delay Interval has elapsed. Situations in which the will message is published include, but are not limited to: An I/O error or network failure detected by the broker. The client fails to communicate within the Keep Alive time. The client closes the network connection without first sending a DISCONNECT packet with a Reason Code `NormalDisconnection`. The broker closes the network connection without first receiving a DISCONNECT packet with a Reason Code `NormalDisconnection`. With this call the plugin's automatic client id generation can be overwritten. If not exists the client creates a session to store its state. If a session is available for this clientId, it loads and uses it. When neither the `WithClientID` or `WithSession` are used, first time connecting to the broker the plugin generates a unique id and will use it for consecutive connections. When neither the `WithClientID` or `WithSession` are used, first time connecting to the broker the plugin generates a unique id and will use it for consecutive connections. Add a user name for authentication purposes. Add a password for authentication purposes. Add both user name and password for authentication purposes. When the Session expires the client and broker need not process the deletion of state atomically. If the Session Expiry Interval is absent the value 0 is used. If it is set to 0, or is absent, the session ends when the network connection is closed. If the *Session Expiry Interval* is 0xFFFFFFFF (uint.MaxValue), the session does not expire. A client that only wants to process messages while connected will call WithCleanStart and set the *Session Expiry Interval* to 0. It will not receive Application Messages published before it connected and has to subscribe afresh to any topics that it is interested in each time it connects. A client might be connecting to a broker using a network that provides intermittent connectivity. This client can use a short *Session Expiry Interval* so that it can reconnect when the network is available again and continue reliable message delivery. If the client does not reconnect, allowing the session to expire, then Application Messages will be lost. When a client connects with a long *Session Expiry Interval*, it is requesting that the broker maintain its MQTT session state after it disconnects for an extended period. Clients should only connect with a long *Session Expiry Interval* if they intend to reconnect to the broker at some later point in time. When a client has determined that it has no further use for the session it should disconnect with a *Session Expiry Interval* set to 0. The client uses this value to limit the number of QoS 1 and QoS 2 publications that it is willing to process concurrently. There is no mechanism to limit the QoS 0 publications that the broker might try to send. The value of Receive Maximum applies only to the current Network Connection. If the Receive Maximum value is absent then its value defaults to 65,535. The maximum packet size the client is willing to accept. If the maximum packet size is not present, no limit on the packet size is imposed beyond the limitations in the protocol as a result of the remaining length encoding and the protocol header sizes. This value indicates the highest value that the client will accept as a topic alias sent by the broker. The client uses this value to limit the number of topic aliases that it is willing to hold on this connection. If topic alias maximum is absent or zero, the broker will not send any topic aliases to the client. If not called, the plugin will use `ushort.MaxValue`(65535). To disable receiving topic aliases from the broker call it with 0. When called with `true` the client request the broker to return Response Information in the ServerConnectAckMessage. The broker can choose not to include Response Information in the connect ack message, even if the client requested it! The client can use this function to indicate whether the ReasonString or UserProperties are sent in the case of failures. If the value of request problem information is `false`, the broker may return a `ReasonString` or `UserProperties` on a *connect acknowledgement* or* disconnect* packet, but must not send a `ReasonString` or `UserProperties` on any packet other than* publish*, *connect acknowledgement* or* disconnect*. If this value is `true`, the broker may return a `ReasonString` or `UserProperties` on any packet where it is allowed. User Properties on the connect packet can be used to send connection related properties from the client to the broker. The meaning of these properties is not defined by this specification. Set the name of the authentication method used for extended authentication. Set the binary data containing authentication data for extended authentication. The contents of this data are defined by the authentication method. https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901121 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901151 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901131 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901141 Quality of Service Levels The message is delivered according to the capabilities of the underlying network. No response is sent by the receiver and no retry is performed by the sender. The message arrives at the receiver either once or not at all. This Quality of Service level ensures that the message arrives at the receiver at least once. This is the highest Quality of Service level, for use when neither loss nor duplication of messages are acceptable. There is an increased overhead associated with QoS 2. Must not be used! Send retained messages at the time of the subscribe. Send retained messages at subscribe only if the subscription does not currently exist. Do not send retained messages at the time of the subscribe Static class that contains helper functions to read various packet types. https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901074 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901205 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901171 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901187 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901100 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901131 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901131 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901151 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901121 https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901217 Container for a server-sent Connect acknowledgement message. True if the server could resume to a previous session. The Server uses this value to limit the number of QoS 1 and QoS 2 publications that it is willing to process concurrently for the Client. It does not provide a mechanism to limit the QoS 0 publications that the Client might try to send. If the Receive Maximum value is absent, then its value defaults to 65,535. Maximum Packet Size the Server is willing to accept Server assigned ClientId. The Client Identifier which was assigned by the Server because a zero length Client Identifier was found in the CONNECT packet. For ClientId - Encoded ClientId mapping. Base64 encoded client id used for directory naming. Contains information about one host: the last used SessionId, and all the known, previously used session Ids. Helper class to manage sessions. Returns with the root directory of the sessions Creates and returns with a Null session. Returns with all the current sessions. Returns true if there's at least one stored session for the given host. Loads the session with the matching clientId, or creates a new one with this id. Delete session from the store and all of its related files. Transport to use raw TCP connections with optional secure (TLS) layer use. Queue for sending packets Event to signal the sending thread. Abstract base class for concreate transport implementations. State of the transport. Parent MQTTClient instance that the transport is created for. Received and parsed packets, sent by the server. Optional for connection cancellation support. Debug context of the transport. Intermediate stream holding incomplete packet bytes. Transport event queue generated on receive/send threads that must be processed on the main thread. https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901285 Data is UTF-8 encoded strings