GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - JustVugg/Mqttcpp: A lightweight and fast C++ library for building MQTT clients and brokers, with support for QoS, authentication, security, persistence, and user/session management.

BranchesTags
Open more actions menu

Latest commit

 

History

6 Commits
6 Commits

Folders and files

NameName
Last commit message
Last commit date
LICENSE
LICENSE
 
 
README.md
README.md
 
 
auth_manager.hpp
auth_manager.hpp
 
 
broker_main.cpp
broker_main.cpp
 
 
buffer.hpp
buffer.hpp
 
 
complete_test.cpp
complete_test.cpp
 
 
dirent.h
dirent.h
 
 
logger.hpp
logger.hpp
 
 
mqtcpp.png
mqtcpp.png
 
 
mqtt_broker.hpp
mqtt_broker.hpp
 
 
mqtt_client.hpp
mqtt_client.hpp
 
 
mqtt_packet.hpp
mqtt_packet.hpp
 
 
persistence.hpp
persistence.hpp
 
 
publisher_test.cpp
publisher_test.cpp
 
 
socket.hpp
socket.hpp
 
 
subscriber_test.cpp
subscriber_test.cpp
 
 
thread_utils.hpp
thread_utils.hpp
 
 
time_utils.hpp
time_utils.hpp
 
 
tls_socket.hpp
tls_socket.hpp
 
 

Repository files navigation

PolymCP Logo


mqttcpp is a modern, lightweight, and high-performance MQTT library written in C++20. It provides both client and broker implementations and includes advanced features such as authentication, retained messages, QoS levels, user and session management, and built-in security controls.


๐Ÿš€ Features

  • Full MQTT 3.1.1 / 5.0 protocol support
  • Integrated broker and client implementation
  • QoS 0, 1, and 2 message delivery
  • Topic wildcards (+ and #)
  • Retained messages and persistence
  • User authentication and access roles
  • Security features (login limits, rate control, etc.)
  • Session handling and concurrent client management
  • Multi-threaded message processing
  • Optional TLS and logging support

๐Ÿงช Test Suite

The project includes a complete test program, complete_test.cpp, which runs a full series of integration tests covering all major features of mqttcpp.

โœ… Included Tests

# Test Description
1 Basic Connection Connect and disconnect a client
2 Single Topic Pub/Sub Basic publish/subscribe workflow
3 Multiple Topics Subscribe to and handle multiple topics
4 Wildcards Verify + and # topic filters
5 Retained Messages Test retained message delivery
6 QoS Levels Check message reliability for QoS 0/1/2
7 Multiple Clients Broadcast a message to several clients
8 Performance Measure throughput with 1000+ messages
9 Authentication Verify user/password login
10 User Management Create and authenticate multiple users
11 Security Features Test brute-force and rate-limit protection
12 Session Management Validate user session limits

๐Ÿ—๏ธ Building the Project

Requirements

  • C++20 compatible compiler (GCC โ‰ฅ 10, Clang โ‰ฅ 12, or MSVC โ‰ฅ 2019)
  • CMake โ‰ฅ 3.16
  • SQLite3
  • OpenSSL (for TLS support)
  • pthread (Linux/macOS)

Build Example

git clone https://github.com/JustVugg/Mqttcpp.git
cd Mqttcpp
mkdir build && cd build
cmake ..
make -j4

This will compile:

  • The Mqtcpp core library
  • The full integration test executable (mqtt_tests)

If you prefer, you can also compile it directly:

g++ complete_test.cpp -std=c++20 -pthread -lsqlite3 -lssl -lcrypto -o mqtt_tests

โ–ถ๏ธ Running the Tests

Run the compiled executable:

./mqtt_tests

Youโ€™ll see each test section printed clearly in the console:

========================================
 Test 2: Single Topic Pub/Sub
========================================
Subscribed to test/topic
Published: Hello MQTT World!
โœ… Single Topic Pub/Sub PASSED

At the end, youโ€™ll get a summary:

==================================================
                 TEST RESULTS                    
==================================================
  Total Tests: 12
  Passed: 12
  Failed: 0

*** ALL TESTS PASSED! The library works perfectly! ***

๐Ÿง  Note: Each test uses a dedicated broker on ports 11883โ€“11887. Make sure no other MQTT services (e.g., Mosquitto) are running on these ports.


โš™๏ธ Example Usage

Start a Broker

#include "mqtt_broker.hpp"
using namespace mqttcpp;

int main() {
    BrokerConfig cfg;
    cfg.port = 1883;
    cfg.require_auth = false;

    MqttBroker broker(cfg);
    broker.start();

    std::cout << "Broker running on port 1883...\n";
    std::cin.get();
}

Connect a Client

#include "mqtt_client.hpp"
using namespace mqttcpp;

int main() {
    MqttClient client("example_client");
    client.connect("localhost", 1883);

    client.subscribe("demo/topic", QOS_0);
    client.publish("demo/topic", "Hello MQTT!", QOS_0);

    std::this_thread::sleep_for(std::chrono::seconds(1));
    client.disconnect();
}

๐Ÿ”’ Security & Authentication

  • User database via SQLite
  • Password policies (length, symbols, etc.)
  • Login attempt limits per IP
  • Role-based authorization
  • Session caps per user
  • Persistent storage and optional encryption

๐Ÿ“ˆ Performance

mqttcpp is optimized for speed:

  • Lock-free message dispatch
  • Threaded network I/O
  • Efficient buffering
  • Minimal latency between clients

The performance test (test 8) demonstrates high throughput even with 1000+ messages exchanged.


๐Ÿงฐ Project Structure

mqttcpp/
โ”œโ”€โ”€ mqtt_broker.hpp
โ”œโ”€โ”€ mqtt_client.hpp
โ”œโ”€โ”€ logger.hpp
โ”œโ”€โ”€ other_source_files.cpp / .hpp
โ””โ”€โ”€ test_basic.cpp

๐Ÿง‘โ€๐Ÿ’ป Author & License

Author: JustVugg License: MIT License

You are free to use, modify, and distribute this library in personal or commercial projects.


โญ Contributing

Pull requests and issues are welcome! If you add features or bug fixes, please include:

  • Clear commit messages
  • Tests for your changes
  • Updated documentation if needed

๐Ÿ’ฌ Feedback

If you encounter a problem or have a feature request, please open an issue on GitHub with:

  • System and compiler details
  • Steps to reproduce
  • Any relevant output or logs

About

A lightweight and fast C++ library for building MQTT clients and brokers, with support for QoS, authentication, security, persistence, and user/session management.

Topics

authenticationbrokerclientcppiotlibrarymqttmqtt-brokermqtt-clientmqtt-cppmqtt-protocolmqttcppperformancepubsubqossecuritysession-management

Resources

Readme
MIT license
Activity

Stars

16 stars

Watchers

0 watching

Forks

4 forks
Report repository

Contributors

Languages

You are visitor 01402503 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.