MQTT Protocol
Native MQTT 3.1.1 and MQTT 5.0 client for Delphi, C++Builder and .NET. Publish-subscribe messaging over WebSocket or raw TCP with QoS 0/1/2, retained messages, last will, topic aliases and shared subscriptions.
Native MQTT 3.1.1 and MQTT 5.0 client for Delphi, C++Builder and .NET. Publish-subscribe messaging over WebSocket or raw TCP with QoS 0/1/2, retained messages, last will, topic aliases and shared subscriptions.
A first-class MQTT implementation that runs everywhere the Delphi / .NET runtime runs — from desktop services to mobile devices, talking to any standard-compliant MQTT broker.
TsgcWSPClient_MQTT
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
Every wire-level feature of MQTT — not just publish and subscribe.
Fire-and-forget, at-least-once and exactly-once delivery. The QoS 2 four-way handshake (PUBLISH → PUBREC → PUBREL → PUBCOMP) is fully exposed via events for retry / audit logic.
Plug the Client property into a TsgcWebSocketClient to run MQTT over WebSockets, or use the native MQTT TCP transport on port 1883 / 8883 — same component, same API.
Mark publications as retained so the broker delivers the last known value to any future subscriber. Set or clear retain per-call on Publish.
LastWillTestament registers a topic + payload the broker will publish if the client drops ungracefully — the canonical way to signal device-offline events.
Topic filters with + (single level) and # (multi level) wildcards: sensors/+/temperature or devices/#.
Session expiry, receive maximum, maximum packet size, topic alias maximum, request response info, user properties — all accessible through ConnectProperties, PublishProperties and SubscribeProperties.
MQTT 5 lets the client (and broker) replace long topic names with a 2-byte integer alias for repeat publications — huge savings for chatty telemetry streams.
MQTT 5 $share/<group>/<topic> distributes incoming messages round-robin across a group of subscribers — the building block for horizontal worker pools.
MQTT 5 ResponseTopic and CorrelationData properties turn pub-sub into asynchronous RPC — built into the events without extra framing.
MQTT 5 AUTH packet with AuthenticationMethod / AuthenticationData for SCRAM-style challenges — call Auth, handle OnMQTTAuth.
HeartBeat sends PINGREQ on a tunable interval. The WatchDog reconnects automatically with exponential backoff and resumes subscriptions.
Run MQTTS on 8883 (raw TCP+TLS) or WSS on 443 with client certificates. TLSOptions.IOHandler picks OpenSSL (cross-platform) or SChannel (Windows kernel TLS).
Lightweight framing, low overhead and stateful sessions make MQTT the default choice for these scenarios.
Sensors stream temperature, vibration, GPS and battery readings over keep-alived MQTT sessions — even on flaky LTE/Cat-M/NB-IoT links.
Bidirectional command channel with QoS 1 for fleet trackers, OBD gateways and EV charging stations — reconnect-and-resume without losing publications.
Replace OPC-UA polling with event-driven publish-subscribe. Topic aliases and shared subscriptions scale to thousands of PLCs and field devices.
Lighting, HVAC, locks and presence sensors talking through Mosquitto or Home Assistant — the Delphi client integrates as easily as any embedded node.
The same component talks to AWS IoT Core, Azure IoT Hub, Google Cloud IoT, IBM Watson, HiveMQ Cloud and EMQX — with X.509 client certificates or SAS tokens.
MQTT-over-WebSocket on RabbitMQ Web-MQTT (port 15675) lets the same broker push to Delphi clients and JS dashboards over a single TLS port.
Long-lived MQTT sessions on iOS/Android with Last Will give you presence and lightweight push without a vendor-specific provider.
Decouple producers and consumers through a central broker. Shared subscriptions round-robin work across a pool of Delphi worker services.
Spec-compliant client — verified against the brokers our customers actually deploy.
X.509 client certificates, SigV4 over WebSocket and the AWS IoT broker quotas. See the dedicated AWS IoT page.
Device-SAS tokens, twin/method topics and DPS provisioning. See the Azure IoT Hub page.
Full MQTT 5 property surface, shared subscriptions, enhanced auth and HiveMQ Cluster.
The reference open-source broker — both MQTT 3.1.1 and 5.0, over TCP or WebSocket.
Massively-scalable broker with shared subscriptions, rule engine and bridge to Kafka. Drop-in.
MQTT-over-WebSocket plugin on port 15675 — the standard pairing for browser + Delphi dashboards.
Clustered MQTT broker built on Erlang/OTP — both MQTT 3.1.1 and 5.0 modes pass the test suite.
Apache ActiveMQ’s built-in MQTT listener and the Artemis broker — multi-protocol coexistence with AMQP, STOMP and JMS.
Pair a TsgcWebSocketClient with TsgcWSPClient_MQTT, wire OnMQTTConnect / OnMQTTPublish, then Subscribe and Publish.
uses
sgcWebSocket, sgcWebSocket_Protocol_MQTT_Client,
sgcWebSocket_Protocol_MQTT_Message;
var
WSClient: TsgcWebSocketClient;
MQTT: TsgcWSPClient_MQTT;
begin
WSClient := TsgcWebSocketClient.Create(nil);
WSClient.Host := 'www.esegece.com';
WSClient.Port := 15675;
MQTT := TsgcWSPClient_MQTT.Create(nil);
MQTT.Client := WSClient;
MQTT.Authentication.Enabled := True;
MQTT.Authentication.UserName := 'sgc';
MQTT.Authentication.Password := 'sgc';
MQTT.OnMQTTConnect := MQTTConnect;
MQTT.OnMQTTPublish := MQTTPublish;
WSClient.Active := True;
end;
procedure TForm1.MQTTConnect(Connection: TsgcWSConnection;
const Session: Boolean; const ReasonCode: Integer;
const ReasonName: string;
const ConnectProperties: TsgcWSMQTTCONNACKProperties);
begin
MQTT.Subscribe('sensors/temperature/#');
end;
procedure TForm1.MQTTPublish(Connection: TsgcWSConnection;
aTopic, aText: string;
PublishProperties: TsgcWSMQTTPublishProperties);
begin
Memo1.Lines.Add(aTopic + ': ' + aText);
end;
// Publish a retained QoS 1 message
MQTT.Publish('sensors/temperature/room1',
'{"value":22.5,"unit":"C"}', mtqsAtLeastOnce, True);
// uses: sgcWebSocket, sgcWebSocket_Protocol_MQTT_Client
TsgcWebSocketClient *WSClient = new TsgcWebSocketClient(this);
WSClient->Host = "www.esegece.com";
WSClient->Port = 15675;
TsgcWSPClient_MQTT *MQTT = new TsgcWSPClient_MQTT(this);
MQTT->Client = WSClient;
MQTT->Authentication->Enabled = true;
MQTT->Authentication->UserName = "sgc";
MQTT->Authentication->Password = "sgc";
MQTT->OnMQTTConnect = MQTTConnect;
MQTT->OnMQTTPublish = MQTTPublish;
WSClient->Active = true;
void __fastcall TForm1::MQTTPublish(TsgcWSConnection *Connection,
UnicodeString aTopic, UnicodeString aText,
TsgcWSMQTTPublishProperties PublishProperties)
{
Memo1->Lines->Add(aTopic + ": " + aText);
}
MQTT->Publish("sensors/temperature/room1",
"{\"value\":22.5,\"unit\":\"C\"}", mtqsAtLeastOnce, true);
using esegece.sgcWebSockets;
var WSClient = new TsgcWebSocketClient();
WSClient.Options.Parameters = "/ws";
var MQTT = new TsgcWSPClient_MQTT();
MQTT.Client = WSClient;
MQTT.Authentication.Enabled = true;
MQTT.Authentication.UserName = "sgc";
MQTT.Authentication.Password = "sgc";
MQTT.HeartBeat.Enabled = true;
MQTT.HeartBeat.Interval = 5;
MQTT.OnMQTTConnect += (conn, session, code, name, props) => MQTT.Subscribe("sensors/temperature/#");
MQTT.OnMQTTPublish += (conn, topic, text, props) => Console.WriteLine(topic + ": " + text);
WSClient.Host = "www.esegece.com";
WSClient.Port = 15675;
WSClient.Active = true;
MQTT.Publish("sensors/temperature/room1",
"{\"value\":22.5,\"unit\":\"C\"}", TmqttQoS.mtqsAtLeastOnce, true);
Authoritative sources for the protocols this component implements.
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.
| Online Help — Protocol_MQTT Full property, method and event reference for this component. | Open | |
| Demo Project — Demos\Protocols\MQTT Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi, C++ Builder and .NET and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |