Everything About XMPP - Extensible Messaging & Presence Protocol
XMPP was one of the powerhouses driving the proliferation of chat applications in the early 2000s. Even now, over two decades later, XMPP is still widely used and supported. How has it stood the test of time? Or better yet, what is XMPP? How does it work? What are its benefits? When should you use XMPP chat apps?
To get a better understanding of what XMPP can do, let's break down what exactly eXtensible Messaging and Presence Protocol means.
With these components, XMPP can handle many of the core functions of a chat app including:
Sending and receiving messages
Broadcasting a user's status
Managing a friends/contact list
And my personal favorite—blocking users from sending you messages
The History of XMPP
XMPP's origins date back to 1999 when Jeremie Miller launched Jabber, an open-source instant messaging software, with the goal of providing an open alternative to the closed instant messaging services.
Jabber's instant messaging and presence functionalities were built on top of a protocol for real-time XML data transmission. Over the years, that protocol evolved into what we now know as XMPP.
In 2002, the foundation running Jabber began the process of turning its core protocol into an Internet Standard. They presented an Internet-Draft documenting the Jabber protocol to the IETF (Internet Engineering Task Force). Then, the foundation submitted the core Jabber protocol to the Internet Standards process and gave control of the protocol over to the IETF under the name of Extensible Messaging and Presence Protocol. And BOOM—XMPP was born.
XMPP Specifications & Standards
The IETF published the core XMPP standards in 2004 in RFC 3920 and RFC 3921. Then, in 2011, the IETF updated the core definition of XMPP in RFC 6120 and RFC 6121.
"RFC, or Request for Comments, is a document that's published by the IETF to officially record and distribute the design decisions, architecture, and technical standards for the internet."
In addition to updating the core, IETF published a few more specifications over the years: RFC 7395, which defines the use of XMPP over WebSockets via a binding; RFC 7590, which allows for the use of TLS (Transport Layer Security); and RFC 7622, which modernized the XMPP addresses.
How Does XMPP Chat Work?
XMPP works on a client-server architecture. This means that when you send a message via XMPP, it's first sent to a server which then routes it to the correct client (user).
How does it know which client to send your message to?
Well, each client connected to an XMPP server is assigned a unique identifier, known as a Jabber ID. The current format of the unique identifier is firstname.lastname@example.org/resource.
The user and domain parts of the unique identifier are pretty straightforward. User is the username of the person and domain.com is the domain of the client that’s sending the message.
Resource refers to the type of device on which the message was sent. For example, mobile vs web. This part of the unique identifier is optional and is often only defined in situations where the client doesn't support every device.
Using this unique identifier, an XMPP server can route each message to the correct client. When a client initiates a session with an XMPP server, it opens a persistent TCP connection and starts an XML stream to the server. Once the client is identified by the server (via the unique identifier) and the connection is accepted, the server then opens an additional XML stream—with this stream going back to the client. The end result is a bi-directional stream of XML data.
XMPP servers can also communicate with other XMPP servers to create a global messaging network called a "federation". A federation allows you to communicate seamlessly with a client on a different XMPP server.
Prefer visuals? An XMPP server-client architecture looks like this:
Now that you’re familiar with the XMPP architecture at a high level, let’s break it down a little further:
As we mentioned earlier, XMPP transmits fragments of XML between two network endpoints. Specifically, the XML fragments transmitted by XMPP, and used for basic communication, are called stanzas. There are 3 types of stanzas used in XMPP and each have their own unique structure and purpose. These are the presence, message, and IQ stanzas.
Just as the name suggests, the presence stanza is used to share the status of a network or user to other users, networks, or servers. The XML fragment looks something like this:
Another straightforward stanza, the message stanza is used to share chat messages between users. It's a “push” mechanism that sends information to other XMPP entities without requiring a response. A message stanza has a type attribute that can have a few different values: chat, normal, group chat, headline, and error. A message stanza can look like this:
Are you free tomorrow?
An IQ stanza is XMPP's method of requesting and modifying data from client to server. It's similar to HTTP's GET and POST request. Each IQ request stanza has an ID value that associates the request with the response stanza. Here’s an example IQ stanza that is requesting the vCard (virtual contact file) of a specific user:
/* Request */ /* Response */ExampleCEOceo@gmail.comimage/pngbinary img data
XMPP allows for asynchronous messaging between users' devices. What does this mean for your app? It means that your users can send multiple messages in a row rather than sending one and needing to wait for a response from the recipient before sending another. It also means that two users don't need to be online at the same time to exchange messages.
With other client-server architectures, the user's (client) device must periodically ping the server to check for new messages. This process is called polling and it detracts from the real-time experience of the user. It can also be quite expensive bandwidth-wise.
Asynchronous messaging gives the user a real-time experience while being efficient and requiring low bandwidth.
XMPP works by creating a persistent TCP (Transmission Control Protocol) connection between a client and server or between one server and another server. Because the connection is persistent, data can be transmitted without reestablishing a connection every time. The low number of connections required reduces bandwidth costs, minimizes network congestion, lowers latency, and lessens CPU and memory usage due to the lower number of connections required.
An often overlooked feature of XMPP is that it's decentralized. You're not reliant on any proprietary server managed by a private company. This means that anyone can create their own XMPP server. You can spin up your own XMPP server on-site, for complete control, or in the cloud, for easy deployment and management.
Unlike other messaging protocols, XMPP is an open standard. That means it's not owned by a specific company. Therefore, you don't need to buy company-specific hardware or software to implement the protocol.
A key feature of XMPP's design is that it can be used to connect multiple types of protocols such as XMPP -> SMS or SMS -> XMPP -> email. This is done using something called gateways.
Gateways are special services that run alongside an XMPP server and act as client proxies. This server-side aspect of gateways means that the client can allow its users to interact with other users on different protocols—no additional code required.
When Should I Use XMPP Protocol for My Chat App?
XMPP is just one of many different chat protocols that you can choose from when selecting the tech stack for your chat application. Choosing the protocol that is the best fit for your specific use case is not an easy task. You need a protocol that will be efficient and effective while meeting your unique requirements.
Think XMPP might be right for you? Here are some common use XMPP use cases:
You're looking for an open-source and standardized protocol
XMPP is an open standard, decentralized, and extensible. This allows you to build XMPP implementations that can easily communicate with each other and even bridge the gap between less flexible protocols. Decentralization allows you to spin up your own XMPP server without the need for 3rd party's involvement.
You need a protocol that offers flexibility when it comes to programming languages
You want a protocol that is widely adopted and generally known in the developer community
XMPP has been in use for over two decades now by large companies and small startups alike. Millions of users across the globe use XMPP every day when they hop onto their favorite chat apps—though most probably don't even realize it.
Given its popularity, it’s not surprising that XMPP has expanded into new use cases. While it's still most often used in messaging and chat applications, XMPP is now also used for VoIP (Voice over IP), gaming, and IoT (Internet of Things) applications.
Real-Life Examples of XMPP Chat Apps
XMPP protocol is one of the most widespread messaging protocols on the internet. If you decide to use XMPP in your project, you'll be joining the ranks of multiple top companies and apps, including:
WhatsApp uses its own proprietary variation of XMPP
Zoom uses XMPP for their chat functionality
Apple uses XMPP to deliver push notifications
Grindr, a geolocation-based dating application, uses XMPP for their chat functionality
Summary & Additional Resources
Phew! Well, we hope now you have a better understanding of XMPP.
Keep in mind that when developing a state-of-the-art chat app, XMPP is just one of many options available to you. Your specific use case and unique requirements will dictate which messaging protocol is best for you. It’s well worth investing time to research and familiarize yourself with a slew of different chat protocols before making a decision.
Cosette Cressler is a passionate content marketer specializing in SaaS, technology, careers, productivity, entrepreneurship and self-development. She helps grow businesses of all sizes by creating consistent, digestible content that captures attention and drives action.