MQTT Protocol
Lightweight publish-subscribe messaging protocol designed for IoT and constrained devices. Full support for MQTT 3.1.1 and MQTT 5.0 specifications.
Lightweight publish-subscribe messaging protocol designed for IoT and constrained devices. Full support for MQTT 3.1.1 and MQTT 5.0 specifications.
MQTT (Message Queuing Telemetry Transport) is a lightweight, open messaging protocol designed for machine-to-machine (M2M) and Internet of Things (IoT) communication.
MQTT uses a publish-subscribe pattern that decouples message senders from receivers, enabling highly scalable communication architectures. Its minimal protocol overhead makes it ideal for constrained devices and low-bandwidth networks. sgcWebSockets provides a complete MQTT implementation supporting both version 3.1.1 and the latest 5.0 specification, including advanced features like shared subscriptions, message expiry, and user properties.
Everything you need to build reliable IoT messaging solutions.
Choose the right delivery guarantee: QoS 0 (at most once), QoS 1 (at least once), or QoS 2 (exactly once) for each message.
The broker stores the last message published to a topic, delivering it immediately to new subscribers so they always have the latest state.
Configure a message that the broker automatically publishes if a client disconnects unexpectedly, enabling graceful failure handling.
Hierarchical topic structure with wildcard support (+ for single level, # for multi-level) enables flexible message routing.
Clean and persistent sessions allow clients to resume subscriptions and receive queued messages after reconnecting.
Connect from web browsers and environments where raw TCP is not available by tunneling MQTT over WebSocket connections.
Secure all MQTT communication with TLS/SSL encryption. Supports certificate-based authentication for enterprise deployments.
MQTT powers communication in thousands of production deployments worldwide.
Connect thousands of sensors reporting temperature, humidity, pressure, and other environmental data with minimal bandwidth overhead.
Control smart home devices — lights, thermostats, locks, and appliances — with reliable, low-latency messaging.
Monitor industrial equipment, production lines, and manufacturing processes with real-time telemetry data collection.
Deliver push notifications to mobile applications with persistent connections and reliable message delivery.
Track vehicle locations, driver behavior, and logistics data in real time across entire fleet operations.
Connect, subscribe, and publish messages in just a few lines of code.
uses
sgcMQTT_Client, sgcMQTT_Classes;
var
MQTTClient: TsgcMQTTClient;
procedure TForm1.FormCreate(Sender: TObject);
begin
MQTTClient := TsgcMQTTClient.Create(nil);
MQTTClient.Host := 'broker.example.com';
MQTTClient.Port := 1883;
MQTTClient.Authentication.Username := 'user';
MQTTClient.Authentication.Password := 'password';
MQTTClient.OnMQTTConnect := OnMQTTConnect;
MQTTClient.OnMQTTPublish := OnMQTTPublish;
MQTTClient.Connect;
end;
procedure TForm1.OnMQTTConnect(Sender: TObject);
begin
// Subscribe to a topic with QoS 1 (at least once)
MQTTClient.Subscribe('sensors/temperature/#', mtqsAtLeastOnce);
end;
procedure TForm1.OnMQTTPublish(Sender: TObject;
aTopic, aText: string);
begin
// Handle incoming messages
Memo1.Lines.Add(aTopic + ': ' + aText);
end;
procedure TForm1.ButtonPublishClick(Sender: TObject);
begin
// Publish a message to a topic
MQTTClient.Publish('sensors/temperature/room1',
'{"value": 22.5, "unit": "C"}', mtqsAtLeastOnce);
end;
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.