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.

What is MQTT?

MQTT (Message Queuing Telemetry Transport) is a lightweight, open messaging protocol designed for machine-to-machine (M2M) and Internet of Things (IoT) communication.

Efficient Messaging for Connected Devices

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.

  • Minimal bandwidth usage with compact binary protocol
  • Publish-subscribe decouples senders and receivers
  • Built-in keep-alive and connection management
  • Supports both TCP and WebSocket transports
BROKER PUB SUB SUB

MQTT Features

Everything you need to build reliable IoT messaging solutions.

Three QoS Levels

Choose the right delivery guarantee: QoS 0 (at most once), QoS 1 (at least once), or QoS 2 (exactly once) for each message.

Retained Messages

The broker stores the last message published to a topic, delivering it immediately to new subscribers so they always have the latest state.

Last Will & Testament

Configure a message that the broker automatically publishes if a client disconnects unexpectedly, enabling graceful failure handling.

Topic-Based Filtering

Hierarchical topic structure with wildcard support (+ for single level, # for multi-level) enables flexible message routing.

Session Persistence

Clean and persistent sessions allow clients to resume subscriptions and receive queued messages after reconnecting.

MQTT over WebSocket

Connect from web browsers and environments where raw TCP is not available by tunneling MQTT over WebSocket connections.

TLS Encryption

Secure all MQTT communication with TLS/SSL encryption. Supports certificate-based authentication for enterprise deployments.

MQTT Use Cases

MQTT powers communication in thousands of production deployments worldwide.

IoT Sensor Networks

Connect thousands of sensors reporting temperature, humidity, pressure, and other environmental data with minimal bandwidth overhead.

Home Automation

Control smart home devices — lights, thermostats, locks, and appliances — with reliable, low-latency messaging.

Industrial Telemetry

Monitor industrial equipment, production lines, and manufacturing processes with real-time telemetry data collection.

Mobile Push Notifications

Deliver push notifications to mobile applications with persistent connections and reliable message delivery.

Fleet Tracking

Track vehicle locations, driver behavior, and logistics data in real time across entire fleet operations.

Delphi MQTT Example

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;

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Ready to Get Started with MQTT?

Download the free trial and start building IoT messaging solutions in minutes.