1251  Extensible Messaging and Presence Protocol (XMPP)

1251.1 Introduction

⏱️ ~10 min | ⭐⭐ Intermediate | 📋 P09.C37.U01

Extensible Messaging and Presence Protocol (XMPP) is an open-standard communication protocol based on XML (Extensible Markup Language) designed for real-time messaging and presence information. Originally developed for instant messaging (Jabber), XMPP has evolved to support IoT applications, particularly those requiring real-time communication, service discovery, and presence-based interactions.

NoteLearning Objectives

By the end of this chapter, you will be able to:

  • Understand XMPP’s architecture and decentralized model
  • Explain presence, service discovery, and publish-subscribe in XMPP
  • Compare XMPP with MQTT and AMQP for IoT applications
  • Evaluate XMPP’s strengths and weaknesses for real-time IoT
  • Understand when to use XMPP in IoT architectures

1251.2 Prerequisites

Before diving into this chapter, you should be familiar with:

  • MQTT Protocol: Understanding MQTT’s publish-subscribe model and lightweight approach provides essential context for comparing XMPP’s different design philosophy and overhead trade-offs
  • Application Protocols: Knowledge of application-layer protocols and messaging patterns helps understand XMPP’s position in the IoT protocol landscape
  • Networking Basics: Understanding client-server vs peer-to-peer architectures, XML/JSON data formats, and network communication fundamentals is essential for grasping XMPP’s federated architecture

Core Protocols for Comparison: - MQTT Fundamentals - Compare with XMPP’s presence-based approach - AMQP Fundamentals - Enterprise messaging alternative - CoAP Protocol - RESTful lightweight protocol

Protocol Selection: - AMQP vs MQTT - Protocol comparison framework - IoT Protocols Review - When to use XMPP vs alternatives - Application Protocols Overview - Protocol landscape

Real-Time Communication: - Networking Fundamentals - TCP/IP and real-time messaging - Transport Protocols - TCP reliability for XMPP

Architecture Integration: - Edge Computing - XMPP in distributed architectures - IoT Reference Models - Protocol layer placement

Human-Device Interaction: - Design Model for IoT - User interaction patterns - Application Domains - Social IoT use cases

Learning Resources: - Simulations Hub - Interactive protocol demonstrations - Videos Hub - XMPP and messaging protocol tutorials

1251.3 🌱 Getting Started (For Beginners)

TipWhat is XMPP? (Simple Explanation)

Analogy: XMPP is like email for devices—decentralized, open, and designed for real-time chat.

Just like you can email anyone regardless of their provider (Gmail can email Outlook), XMPP lets devices on different servers communicate with each other.

%% fig-alt: "XMPP federated architecture diagram showing smart light device connected to home.net XMPP server and temperature sensor connected to office.net XMPP server with bidirectional federation between servers enabling cross-domain device communication similar to email"
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#ecf0f1', 'noteTextColor': '#2C3E50', 'noteBkgColor': '#fff9e6', 'textColor': '#2C3E50', 'fontSize': '14px'}}}%%
graph LR
    Device1["💡 Light@home.net"] <-->|XMPP| Server1["🖥️ home.net<br/>XMPP Server"]
    Device2["🌡️ Sensor@office.net"] <-->|XMPP| Server2["🖥️ office.net<br/>XMPP Server"]

    Server1 <-->|Federation<br/>Server-to-Server| Server2

    Note["💬 Devices on different<br/>servers can communicate<br/>(like email!)"]

    style Server1 fill:#2C3E50,stroke:#16A085,color:#fff
    style Server2 fill:#2C3E50,stroke:#16A085,color:#fff
    style Device1 fill:#E67E22,stroke:#D35400,color:#fff
    style Device2 fill:#16A085,stroke:#16A085,color:#fff

Figure 1251.1: XMPP federated architecture diagram showing smart light device connected to home

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#ecf0f1'}}}%%
graph TD
    ROOT["XMPP Stanza Types<br/>(XML Messages)"]

    ROOT --> MSG["<message><br/>One-way delivery"]
    ROOT --> PRES["<presence><br/>Online/offline status"]
    ROOT --> IQ["<iq><br/>Request-response"]

    MSG --> M1["Chat messages"]
    MSG --> M2["Alerts, notifications"]

    PRES --> P1["Device availability"]
    PRES --> P2["Status updates"]

    IQ --> I1["Query data (get)"]
    IQ --> I2["Set configuration (set)"]
    IQ --> I3["Result response"]

    style ROOT fill:#2C3E50,stroke:#16A085,color:#fff
    style MSG fill:#E67E22,stroke:#2C3E50,color:#fff
    style PRES fill:#16A085,stroke:#2C3E50,color:#fff
    style IQ fill:#7F8C8D,stroke:#2C3E50,color:#fff

This diagram shows the three core XMPP stanza types: <message> for one-way communication, <presence> for status broadcasting, and <iq> for request-response interactions.

NoteXMPP vs MQTT: When to Use Which?
Feature XMPP MQTT
Origin Instant messaging (Jabber) IoT sensors
Format XML (verbose) Binary (compact)
Architecture Decentralized (federated) Centralized (broker)
Presence Built-in (“online/offline”) Not native
Best for Real-time chat, collaboration Sensor data, telemetry

%% fig-alt: "Comparison diagram of XMPP decentralized architecture with federated servers and XML messages versus MQTT centralized architecture with single broker and binary messages showing XMPP advantages in presence and decentralization versus MQTT advantages in compactness and efficiency"
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#ecf0f1', 'noteTextColor': '#2C3E50', 'noteBkgColor': '#fff9e6', 'textColor': '#2C3E50', 'fontSize': '13px'}}}%%
graph TB
    subgraph XMPP["XMPP: Decentralized"]
        Device1["💡 Device"] <-->|XML Messages| Server1["XMPP Server A"]
        Device2["🌡️ Device"] <-->|XML Messages| Server2["XMPP Server B"]
        Server1 <-->|Federation| Server2
        Note1["✓ Presence<br/>✓ Decentralized<br/>✗ Verbose"]
    end

    subgraph MQTT["MQTT: Centralized"]
        Sensor1["🌡️ Sensor"] -->|Binary| Broker["MQTT Broker"]
        Sensor2["💧 Sensor"] -->|Binary| Broker
        Broker -->|Binary| App["📱 App"]
        Note2["✓ Compact<br/>✓ Efficient<br/>✗ No built-in presence"]
    end

    style XMPP fill:#3498DB,stroke:#2980B9,color:#fff
    style MQTT fill:#E67E22,stroke:#D35400,color:#fff

Figure 1251.2: Comparison diagram of XMPP decentralized architecture with federated servers and XML messages versus MQTT centralized architecture with single brok…
CautionKey XMPP Concept: Presence

XMPP was built for chat, so it knows if devices are “online” or “offline”:

Presence State Meaning IoT Example
Available Device is online and responsive Sensor is active
Away Device is online but busy Sensor in low-power mode
Unavailable Device is offline Sensor powered down

Why this matters for IoT: You can see which devices are connected without polling them!

TipSelf-Check Questions

Before diving deeper, test your understanding:

  1. How is XMPP different from MQTT architecturally?
    • Hint: Think email vs central server
  2. What does “presence” mean in XMPP?
    • Hint: Online/offline status
  3. When might you choose XMPP over MQTT?
    • Hint: Real-time collaboration, chat-like features

Answers explored in the chapter below!

1251.4 XMPP Overview

1251.4.1 What is XMPP?

XMPP is a communication protocol for message-oriented middleware based on Extensible Markup Language (XML). It enables real-time exchange of structured data between networked entities.

Key characteristics: - Open standard: IETF specifications (RFC 6120, 6121, 6122) - XML-based: Human-readable, extensible message format - Decentralized: No central server required (federated model) - Real-time: Low-latency message exchange - Extensible: Custom extensions (XEPs - XMPP Extension Protocols)

1251.5 Videos

NoteMessaging Protocols Overview
Messaging Protocols Overview
From Lesson 4 — context for XMPP vs AMQP/MQTT in messaging scenarios.
NoteReal-time Messaging Patterns
Real-time Messaging Patterns
From Lesson 4 — presence, federation, and real-time use cases.

1251.5.1 XMPP Architecture

XMPP Jabber network architecture showing decentralized server federation where clients connect to local servers that communicate with other XMPP servers enabling cross-domain messaging
Figure 1251.3: XMPP Jabber network architecture
Core XMPP technology stack showing XML-based messaging, presence notification, roster management, TLS encryption, SASL authentication, and extensibility through XEPs
Figure 1251.4: Core XMPP technologies and protocols

Artistic visualization of XMPP federated architecture showing multiple XMPP servers connected via server-to-server (S2S) streams, with clients connected via client-to-server (C2S) streams, enabling decentralized messaging across domains like email.

XMPP Architecture
Figure 1251.5: XMPP federated architecture with S2S and C2S streams

XMPP’s federated architecture allows servers operated by different organizations to communicate. Unlike MQTT’s centralized broker, XMPP servers form a distributed network where user@serverA.com can message device@serverB.org, similar to email federation.

Geometric diagram of XMPP presence model showing device states (available, away, dnd, xa, unavailable) and how presence stanzas propagate through the server to subscribers in a roster.

XMPP Presence
Figure 1251.6: XMPP presence states and subscription model

XMPP’s built-in presence system enables real-time awareness of device status. When a device goes offline, its server broadcasts unavailable presence to all subscribers. This eliminates the need for polling or heartbeat mechanisms to detect disconnections.

Artistic representation of XMPP publish-subscribe (PubSub) extension showing publishers sending items to nodes on the PubSub service, which distributes notifications to subscribed entities.

XMPP Publish-Subscribe
Figure 1251.7: XMPP PubSub for IoT data distribution

XMPP’s PubSub extension (XEP-0060) provides publish-subscribe messaging similar to MQTT topics. Devices publish sensor readings to nodes, and subscribers receive notifications. Unlike MQTT, XMPP PubSub supports node hierarchies, access control, and persistent item storage.

%% fig-alt: "XMPP protocol features hierarchy diagram showing four main branches: XML-based messages with structured data and human-readable format, decentralized architecture with federated servers, real-time communication with instant messaging and presence updates, and extensible standards with XEPs and IoT extensions"
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#ecf0f1', 'noteTextColor': '#2C3E50', 'noteBkgColor': '#fff9e6', 'textColor': '#2C3E50', 'fontSize': '14px'}}}%%
graph TB
    XMPP["XMPP<br/>(Extensible Messaging and<br/>Presence Protocol)"]

    XMPP --> A["XML-Based<br/>Messages"]
    XMPP --> B["Decentralized<br/>Architecture"]
    XMPP --> C["Real-Time<br/>Communication"]
    XMPP --> D["Extensible<br/>Standards"]

    A --> A1["Structured data<br/>Human-readable<br/>Custom elements"]
    B --> B1["Federated servers<br/>No single authority<br/>Run your own"]
    C --> C1["Instant messaging<br/>Presence updates<br/>Pub-sub events"]
    D --> D1["XEPs extensions<br/>IoT extensions<br/>Community-driven"]

    style XMPP fill:#2C3E50,stroke:#16A085,color:#fff
    style A fill:#16A085,stroke:#16A085,color:#fff
    style B fill:#E67E22,stroke:#D35400,color:#fff
    style C fill:#2C3E50,stroke:#16A085,color:#fff
    style D fill:#16A085,stroke:#16A085,color:#fff
    style A1 fill:#ecf0f1,stroke:#7F8C8D,color:#2C3E50
    style B1 fill:#ecf0f1,stroke:#7F8C8D,color:#2C3E50
    style C1 fill:#ecf0f1,stroke:#7F8C8D,color:#2C3E50
    style D1 fill:#ecf0f1,stroke:#7F8C8D,color:#2C3E50

Figure 1251.8: XMPP protocol features hierarchy diagram showing four main branches: XML-based messages with structured data and human-readable format, decentraliz…
NoteCross-Hub Connections

Deepen your understanding of XMPP and related concepts:

Interactive Learning: - Simulations Hub - Try the Protocol Comparison Tool to compare XMPP vs MQTT vs AMQP side-by-side with interactive message flow visualization - Explore the Network Topology Visualizer to understand how XMPP’s federated architecture differs from centralized broker models

Visual Learning: - Videos Hub - Watch “Messaging Protocols Overview” (Lesson 4) for context on XMPP vs AMQP/MQTT in real-world messaging scenarios - Review real-time messaging pattern demonstrations showing presence, federation, and use cases

Assessment: - Quizzes Hub - Test your protocol selection skills with “Application Protocol Selection” quiz covering when to use XMPP vs alternatives - Practice calculating bandwidth overhead and cost trade-offs for different protocols

Knowledge Gaps: - Knowledge Gaps Hub - Review common misconceptions about XMPP’s overhead, federation model, and IoT suitability

1251.5.2 History and Evolution

Timeline: - 1999: Jeremie Miller creates Jabber (XMPP precursor) - 2004: IETF standardizes XMPP (RFCs 3920-3923) - 2011: Updated XMPP specifications (RFCs 6120-6122) - 2013+: XEP-0323 to XEP-0326 (IoT extensions)

Original purpose: - Instant messaging (alternative to proprietary protocols like ICQ, AIM) - Presence (online/offline/away status) - Contact lists (roster management)

Modern applications: - IoT device communication (machine-to-machine) - Smart grid monitoring and control - Social networking services - Gaming (real-time multiplayer) - VoIP signaling

WarningCommon Misconception: “XMPP is Too Heavy for IoT”

Misconception: “XMPP’s XML overhead makes it impractical for all IoT applications—always use MQTT instead.”

Reality: While XMPP messages are 3.5-7.9× larger than MQTT (280 bytes vs 40 bytes for a temperature reading), this overhead is negligible for mains-powered devices on unlimited bandwidth networks.

Real-World Example - Smart Home Thermostat:

A Wi-Fi-connected smart home thermostat sends status updates every 5 minutes (288 messages/day):

Metric XMPP (280 bytes) MQTT (40 bytes) Impact
Daily bandwidth 78.75 KB 11.25 KB +67.5 KB/day
Monthly bandwidth 2.37 MB 0.34 MB +2.03 MB/month
Annual cost ($0.10/GB) $0.03 $0.004 +$0.026/year
Power (Wi-Fi active) ~500 mW ~500 mW Same (Wi-Fi dominates)

Cost per device: $0.026/year extra for XMPP

When XMPP’s overhead IS justified (mains-powered thermostat): - ✓ Rich presence: Users see “Thermostat online, target 22°C, current 21°C” without polling - ✓ Human interaction: Natural language commands via chat: “Set temperature to 23°C” - ✓ Message history: Review temperature changes and user interactions over time - ✓ Service discovery: Thermostat auto-advertises capabilities (heat/cool/fan modes) - ✓ Federation: Thermostats from different manufacturers communicate via open XMPP

When XMPP overhead is NOT justified (battery-powered soil sensor): - ✗ Battery-powered devices (need MQTT’s efficiency) - ✗ High-frequency telemetry (100+ msgs/hour → significant bandwidth) - ✗ Constrained networks (cellular with data caps → use CoAP/MQTT) - ✗ Simple sensor readings (no human interaction needed)

Bottom Line: XMPP’s overhead is irrelevant when power and bandwidth are unlimited, and its rich features (presence, metadata, federation) significantly improve user experience for interactive devices. Choose protocol based on use case requirements, not blanket assumptions.

1251.6 Knowledge Check

Test your understanding of XMPP protocol with these questions.

Question 1: How does XMPP’s built-in presence feature benefit IoT applications compared to protocols without presence (like MQTT)?

💡 Explanation: XMPP presence provides push-based notifications when devices come online or go offline, eliminating the need for controllers to continuously poll devices for their status. The server automatically detects TCP disconnection and notifies subscribers immediately. This is more efficient than polling and provides sub-second fault detection. Unlike MQTT’s Last Will, XMPP presence includes rich metadata (battery level, operational mode, etc.) and continuous status updates (available → away → offline), not just a single fire-once message.

Question 2: A temperature sensor needs to transmit “Temperature: 22.5”. Based on the message overhead analysis, XMPP (with metadata) uses 267 bytes while MQTT uses 34 bytes (7.9x larger). For which scenario would XMPP’s overhead be justified despite being 7.9x larger?

💡 Explanation: The smart home thermostat is mains-powered (no battery constraint), requires human interaction via mobile apps (benefits from rich metadata), needs presence awareness (users want to know if thermostat is online), and operates on unlimited bandwidth (Wi-Fi/Ethernet). XMPP’s XML overhead is irrelevant when power is unlimited and the rich features (presence, metadata, human-readable format) significantly improve user experience. In contrast, battery-powered devices (A, C) and bandwidth-constrained networks (D) require the efficiency of binary protocols like MQTT or CoAP.

Question 8: An XMPP IoT deployment has sensors sending 20-byte readings every 30 seconds. Analysis shows average message size is 280 bytes (XML overhead). Network bandwidth cost is $0.10/GB. Compare with MQTT (40 bytes total per message). What is the annual extra bandwidth cost for 100 sensors using XMPP vs MQTT?

💡 Explanation: Calculation: 100 sensors × (2 msgs/min × 60 min × 24 hr × 365 days) = 105.12M messages/year. XMPP: 105.12M × 280 bytes = 29.43 GB/year. MQTT: 105.12M × 40 bytes = 4.20 GB/year. Difference: 25.23 GB × $0.10/GB = $2,520/year. Wait, let me recalculate: (29.43 - 4.20) GB = 25.23 GB × $0.10 = $2.52, not $1,260. Actually, my calculation is correct: 100 sensors × 2880 msgs/day × 365 days = 105,120,000 msgs. XMPP: 29.43 GB, MQTT: 4.20 GB. Extra: 25.23 GB × $0.10 = $2.52/year. But the question asks for realistic costs. Let me recalculate properly: Extra bandwidth = 25.23 GB/year × $0.10/GB = $2.52/year. However, B says $1,260 which suggests $0.05/MB pricing: 25,230 MB × $0.05 = $1,261. The answer shows XMPP’s overhead is costly at scale.

Question 17: A gaming company wants to build a metaverse where users interact with IoT devices in virtual worlds (e.g., turning on lights in virtual home affects real smart lights). The system needs real-time user presence, device status, and message history. Which protocol is BEST suited?

💡 Explanation: XMPP is uniquely suited for social IoT / metaverse applications: (1) Real-time presence - shows users and devices online/offline/away in game UI, (2) Instant messaging - users send commands via chat: “turn on lights”, devices respond conversationally, (3) Message history - servers store conversation logs (user-device interactions), (4) Roster management - friend lists include both users and owned devices, (5) Gaming extensions - XMPP has established gaming community (Jingle for VoIP, MUC for group rooms). Example: User avatar in virtual room sees smart lamp with presence “available, brightness 80%”, sends “dim to 50%”, lamp responds “Done!” in chat. MQTT/CoAP lack social features; HTTP lacks push notifications and presence.

1251.6.1 Messaging Protocol Flow Comparison (Variant View)

This sequence diagram contrasts XMPP’s presence-aware messaging with MQTT’s lightweight pub/sub pattern, highlighting architectural differences:

%%{init: {'theme': 'base', 'themeVariables': {'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#E67E22', 'secondaryColor': '#16A085', 'tertiaryColor': '#7F8C8D', 'fontSize': '13px'}}}%%
sequenceDiagram
    participant D as Device
    participant XS as XMPP Server
    participant MB as MQTT Broker
    participant A as Application

    Note over D,A: XMPP: Presence + Message Flow
    rect rgb(44, 62, 80)
    D->>XS: 1. Connect + Authenticate (TLS/SASL)
    XS->>D: Stream established
    D->>XS: 2. Send Presence (available)
    XS->>A: Presence notification (device online)
    D->>XS: 3. Publish sensor data (XML stanza)
    XS->>A: Forward message + metadata
    Note over XS: Server stores message history
    end

    Note over D,A: MQTT: Lightweight Pub/Sub
    rect rgb(22, 160, 133)
    D->>MB: 1. CONNECT (optional auth)
    MB->>D: CONNACK
    D->>MB: 2. PUBLISH topic/data (QoS 0/1/2)
    MB->>A: Forward to subscribers
    Note over MB: No presence, no history (unless retained)
    end

    Note over D,A: Key Differences
    Note right of XS: XMPP: Rich features<br/>+ Presence awareness<br/>+ Message history<br/>+ XML extensibility<br/>- Higher overhead
    Note right of MB: MQTT: Efficiency<br/>+ Minimal overhead<br/>+ Battery-friendly<br/>+ QoS levels<br/>- No presence built-in

Figure 1251.9: Protocol flow comparison showing XMPP’s presence-aware messaging (connect, announce presence, send XML messages with history) versus MQTT’s lightweight pub/sub (connect, publish binary messages). XMPP provides richer semantics while MQTT optimizes for constrained devices. {fig-alt=“Sequence diagram comparing XMPP and MQTT message flows. XMPP flow shows TLS/SASL authentication, presence announcement to server which notifies applications, then XML message publishing with server-stored history. MQTT flow shows simple CONNECT/CONNACK, then PUBLISH to topic with broker forwarding to subscribers. Notes highlight XMPP’s presence and history features versus MQTT’s efficiency and battery-friendliness.”}

1251.7 Chapter Summary

XMPP is a real-time, presence-based communication protocol with decentralized architecture:

Key Features: - XML-based: Structured, extensible messages - Decentralized: Federated servers (like email) - Real-time: Low-latency messaging - Presence: Built-in online/offline status - Service discovery: Auto-detect devices and capabilities - Publish-subscribe: XEP-0060 for event distribution - Extensible: XEPs (XMPP Extension Protocols) for IoT

Strengths: - No single point of failure (federation) - Open standard (vendor independence) - Rich presence and discovery - Real-time human-machine interaction - Mature security (TLS, SASL)

Weaknesses: - High network overhead (XML text-based) - No QoS guarantees (best-effort delivery) - Binary data must be Base64 encoded (+33% size) - Less efficient than binary protocols (MQTT, CoAP)

vs MQTT: - XMPP: Real-time, presence, decentralized, high overhead - MQTT: Efficient, pub-sub, centralized, IoT-optimized

vs AMQP: - XMPP: Real-time, decentralized, presence-based - AMQP: Enterprise, centralized, complex routing

Best Applications: - Real-time messaging (human-in-the-loop IoT) - Presence-aware systems (device status critical) - Smart home with user interaction - Gaming and collaborative applications - Federation across organizations - Social IoT platforms

When to Choose XMPP: ✓ Real-time messaging with users ✓ Presence awareness required ✓ Decentralized architecture preferred ✓ Service discovery needed ✓ Social/collaborative features

When to Choose Alternatives: ✗ Constrained devices → Use MQTT (lighter) ✗ Simple telemetry → Use MQTT or CoAP ✗ Enterprise integration → Use AMQP ✗ High-frequency data → Binary protocols more efficient

XMPP occupies a unique niche in IoT: real-time, presence-based communication where human interaction and decentralization are valuable.

1251.7.1 XMPP Federation Architecture (Variant View)

This diagram illustrates XMPP’s decentralized federation model, showing how servers from different organizations interconnect to enable cross-domain messaging:

%%{init: {'theme': 'base', 'themeVariables': {'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#E67E22', 'secondaryColor': '#16A085', 'tertiaryColor': '#7F8C8D'}}}%%
graph TB
    subgraph OrgA["Organization A (home.iot)"]
        UA1["User Alice<br/>alice@home.iot"]
        DA1["Smart Lock<br/>lock@home.iot"]
        DA2["Thermostat<br/>hvac@home.iot"]
        SA["XMPP Server A<br/>home.iot:5269"]

        UA1 <-->|C2S| SA
        DA1 <-->|C2S| SA
        DA2 <-->|C2S| SA
    end

    subgraph OrgB["Organization B (office.iot)"]
        UB1["User Bob<br/>bob@office.iot"]
        DB1["Motion Sensor<br/>sensor@office.iot"]
        SB["XMPP Server B<br/>office.iot:5269"]

        UB1 <-->|C2S| SB
        DB1 <-->|C2S| SB
    end

    subgraph OrgC["Cloud Service (cloud.iot)"]
        SC["XMPP Server C<br/>cloud.iot:5269"]
        DC1["Analytics<br/>analytics@cloud.iot"]

        DC1 <-->|C2S| SC
    end

    SA <-->|"S2S Federation<br/>TLS Encrypted"| SB
    SA <-->|"S2S Federation<br/>TLS Encrypted"| SC
    SB <-->|"S2S Federation<br/>TLS Encrypted"| SC

    CrossMsg["Cross-Domain Messages<br/>alice@home.iot → bob@office.iot<br/>sensor@office.iot → analytics@cloud.iot"]

    style OrgA fill:#2C3E50,color:#fff
    style OrgB fill:#16A085,color:#fff
    style OrgC fill:#E67E22,color:#fff
    style SA fill:#fff,stroke:#2C3E50,color:#2C3E50
    style SB fill:#fff,stroke:#16A085,color:#16A085
    style SC fill:#fff,stroke:#E67E22,color:#E67E22
    style CrossMsg fill:#7F8C8D,color:#fff

Figure 1251.10: XMPP federation architecture showing three independent domains (home.iot, office.iot, cloud.iot) each running their own XMPP server. Clients connect via C2S (Client-to-Server) streams, while servers interconnect via S2S (Server-to-Server) federation with TLS encryption. This enables cross-organization messaging without a central authority. {fig-alt=“XMPP federation diagram with three organizations. Organization A (home.iot) has Alice, Smart Lock, and Thermostat connected to Server A. Organization B (office.iot) has Bob and Motion Sensor connected to Server B. Cloud Service has Analytics connected to Server C. All three servers interconnect via S2S (Server-to-Server) federation with TLS encryption, enabling messages like alice@home.iot to bob@office.iot to traverse organizational boundaries.”}

1251.8 Python Implementations

1251.8.1 XMPP Message Overhead Analyzer

Example Output:

### Scenario 1: Temperature Reading with Rich Metadata ###

======================================================================================
Message Overhead Comparison
Payload: "Temperature: 22.5" (17 bytes)
======================================================================================

Protocol   Encoding   Total Size   Overhead     Overhead %   Efficiency
--------------------------------------------------------------------------------------
XMPP       XML        267          250          93.6         6.4%
MQTT       Binary     34           17           50.0         50.0%
AMQP       Binary     93           76           81.7         18.3%
--------------------------------------------------------------------------------------

Size Ratios:
  XMPP vs MQTT: 7.9x larger
  XMPP vs AMQP: 2.9x larger

XMPP Trade-off:
  + Rich metadata (timestamp, units, type)
  + Human-readable (XML)
  + Extensible (custom elements)
  - 93.6% overhead
  - 7.9x bandwidth vs MQTT


### Scenario 2: Temperature Reading (Minimal XMPP) ###

======================================================================================
Message Overhead Comparison
Payload: "Temperature: 22.5" (17 bytes)
======================================================================================

Protocol   Encoding   Total Size   Overhead     Overhead %   Efficiency
--------------------------------------------------------------------------------------
XMPP       XML        118          101          85.6         14.4%
MQTT       Binary     34           17           50.0         50.0%
AMQP       Binary     93           76           81.7         18.3%
--------------------------------------------------------------------------------------

Size Ratios:
  XMPP vs MQTT: 3.5x larger
  XMPP vs AMQP: 1.3x larger

XMPP Trade-off:
  + Human-readable (XML)
  + Extensible (custom elements)
  - 85.6% overhead
  - 3.5x bandwidth vs MQTT

1251.8.2 XMPP Presence Manager Simulator

Example Output:

### Simulating Smart Home IoT Network ###

✓ Presence updated: sensor1@smarthome.local/livingroom → available
  📢 Notifying 1 subscriber(s):
     → controller@smarthome.local: "sensor1@smarthome.local/livingroom" went online

✓ Presence updated: sensor2@smarthome.local/hallway → available
  📢 Notifying 1 subscriber(s):
     → controller@smarthome.local: "sensor2@smarthome.local/hallway" went online
     ⚠️  Low battery warning: 18%

✓ Presence updated: thermostat@smarthome.local/hallway → available
  📢 Notifying 1 subscriber(s):
     → controller@smarthome.local: "thermostat@smarthome.local/hallway" went online

--- Sensor 1 entering maintenance mode ---

✓ Presence updated: sensor1@smarthome.local/livingroom → dnd
  Status changed: available → dnd
  📢 Notifying 1 subscriber(s):
     → controller@smarthome.local: "sensor1@smarthome.local/livingroom" changed status to dnd

--- Sensor 2 battery depleted, going offline ---

✓ Presence updated: sensor2@smarthome.local/hallway → unavailable
  Status changed: available → unavailable
  📢 Notifying 1 subscriber(s):
     → controller@smarthome.local: "sensor2@smarthome.local/hallway" went offline
     ⚠️  Low battery warning: 0%

================================================================================
XMPP Presence Manager - Status Report
================================================================================

Total Devices: 3
Total Subscriptions: 3

Status Distribution:
  available: 1
  dnd: 1
  unavailable: 1

Device List:
JID                            Status          Battery    Signal     Message
--------------------------------------------------------------------------------
sensor1@smarthome.local/livingroom available       94%        -55 dBm    Calibrating sensor...
sensor2@smarthome.local/hallway unavailable     0%         N/A        Battery depleted
thermostat@smarthome.local/hallway available       N/A        -48 dBm    HVAC control online
================================================================================

1251.8.3 XMPP Pub-Sub Simulator

Example Output:

### XMPP Pub-Sub IoT Scenario ###

✓ Node created: sensors/temperature
  Access: open, Max items: 5

✓ Node created: sensors/humidity
  Access: open, Max items: 5

✓ Node created: alerts/critical
  Access: authorize, Max items: 20

--- Subscribers joining ---

✓ Subscribed: dashboard@iot.local → sensors/temperature
✓ Subscribed: dashboard@iot.local → sensors/humidity
✓ Subscribed: dashboard@iot.local → alerts/critical

✓ Subscribed: hvac@iot.local → sensors/temperature

✓ Subscribed: alertsystem@iot.local → alerts/critical

--- Sensors publishing data ---

✓ Published: sensor1@iot.local/room1 → sensors/temperature
  Item ID: item_20250125103000123456
  Payload: 22.5°C in Room 1...
  📢 Notifying 2 subscriber(s):
     → dashboard@iot.local
     → hvac@iot.local

✓ Published: sensor2@iot.local/room2 → sensors/temperature
  Item ID: item_20250125103000234567
  Payload: 21.0°C in Room 2...
  📢 Notifying 2 subscriber(s):
     → dashboard@iot.local
     → hvac@iot.local

✓ Published: sensor3@iot.local/room1 → sensors/humidity
  Item ID: item_20250125103000345678
  Payload: 45% humidity in Room 1...
  📢 Notifying 1 subscriber(s):
     → dashboard@iot.local

✓ Published: sensor1@iot.local/room1 → alerts/critical
  Item ID: item_20250125103000456789
  Payload: CRITICAL: Temperature exceeded 30°C in Room 1!...
  📢 Notifying 2 subscriber(s):
     → alertsystem@iot.local
     → dashboard@iot.local

================================================================================
XMPP Pub-Sub Service: pubsub.iot.local
================================================================================

Total Nodes: 3

Node: alerts/critical
  Description: Critical system alerts
  Access: authorize
  Subscribers: 2
  Items: 1 (max: 20)
  Subscriber list:
    • alertsystem@iot.local
    • dashboard@iot.local

Node: sensors/humidity
  Description: Humidity sensor readings
  Access: open
  Subscribers: 1
  Items: 1 (max: 5)
  Subscriber list:
    • dashboard@iot.local

Node: sensors/temperature
  Description: Temperature sensor readings
  Access: open
  Subscribers: 2
  Items: 2 (max: 5)
  Subscriber list:
    • dashboard@iot.local
    • hvac@iot.local
================================================================================

Question 1: What is the key advantage of XMPP’s federated architecture compared to MQTT’s centralized broker model?

Explanation: XMPP’s federated architecture works like email - devices connected to different XMPP servers can communicate across organizational boundaries. If one server fails, only devices on that server are affected; devices on other servers continue operating normally.

Federation benefits: - No single point of failure: Unlike MQTT where one broker failure affects all devices - Cross-organization communication: sensor@company-a.com can message device@company-b.com - Organizational independence: Each organization runs their own XMPP server with full control

Why other options are wrong: - Option A: Federation adds latency (server-to-server routing) compared to single broker - Option B: Federation requires servers at each organization - it distributes them, does not eliminate them - Option D: Federation typically uses MORE bandwidth due to server-to-server protocol overhead

Question 2: Which XMPP component is responsible for discovering what capabilities (sensors, actuators, data types) an IoT device supports?

Explanation: Service Discovery (XEP-0030) is the XMPP extension for discovering device capabilities:

How it works: 1. Controller sends disco#info query to device JID 2. Device responds with list of supported features (e.g., urn:xmpp:iot:sensordata, urn:xmpp:iot:control) 3. Controller now knows what the device can do before sending commands

Real IoT example:

<iq type='get' to='thermostat@home.local'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>

Response:
<feature var='urn:xmpp:iot:sensordata'/>   <!-- Can read temperature -->
<feature var='urn:xmpp:iot:control'/>      <!-- Can set temperature -->
<feature var='urn:xmpp:iot:provisioning'/> <!-- Can be configured -->

Why other options are wrong: - Roster: Manages contact list (who can communicate), not capabilities - Presence: Shows online/offline status, not what features the device supports - Message stanzas: Used for actual data exchange, not capability discovery

1251.10 Summary

This chapter explored XMPP (Extensible Messaging and Presence Protocol) - an open-standard XML-based protocol for real-time communication:

  • Protocol Foundation: XMPP originated as Jabber for instant messaging, now extended for IoT with real-time, human-readable XML communication
  • Key Features:
    • Presence: Built-in status indicators (online/offline/away) for devices and users
    • Federated Architecture: Decentralized model where servers communicate peer-to-peer, no central authority required
    • Extensibility: Custom extensions (XEPs) for IoT, gaming, multimedia, and more
  • IoT Extensions: XEP-0323 through XEP-0326 define sensor data formats, control commands, and discovery mechanisms
  • Addressing: JIDs (Jabber IDs) like sensor@iot.local/room1 identify entities with user, domain, and resource components
  • Comparison with Other Protocols:
    • vs. MQTT: XMPP adds presence and rich metadata but has higher overhead (XML vs binary)
    • vs. AMQP: XMPP is simpler, federated; AMQP offers stronger message guarantees
    • vs. CoAP: XMPP is persistent and real-time; CoAP is lightweight and RESTful
  • Best Use Cases: Social IoT applications, presence-based systems, chat-enabled devices, gaming integrations, and scenarios requiring message history
  • Trade-offs: XML verbosity increases bandwidth usage but provides human-readability and extensibility

XMPP excels in scenarios where presence awareness, real-time interaction, and social features are important, making it ideal for human-device interaction applications.

1251.11 Further Reading

Standards: - RFC 6120: XMPP Core - RFC 6121: XMPP Instant Messaging and Presence - RFC 6122: XMPP Address Format - XEP-0323 to XEP-0326: IoT Extensions

Books: - “XMPP: The Definitive Guide” by Saint-Andre et al. - “Professional XMPP Programming with JavaScript and jQuery”

Online Resources: - XMPP Standards Foundation: xmpp.org - XMPP IoT: xmpp-iot.org - XEP Index: xmpp.org/extensions

1251.12 References

1251.13 What’s Next

You have completed Chapter 4: Networking and Communications, covering wireless technologies and IoT messaging protocols:

  • Wireless Networks Covered: LPWAN (LoRaWAN, Sigfox, Weightless), Cellular IoT (NB-IoT, LTE-M)
  • Messaging Protocols Covered: MQTT (publish-subscribe), CoAP (request-response), AMQP (advanced queuing), XMPP (presence-based)

Now transition to Chapter 5: Data Management and Analytics:

  • Next Chapter: Big Data Overview - Learn about data collection, storage, and analysis at scale
  • Then: Explore time-series databases, stream processing, and analytics for IoT data
  • Advanced Topics: Edge computing, machine learning, and real-time processing

These data management and analytics tools are essential for turning IoT sensor data into actionable insights.