XMPP: introduction
Translation of the original in Catalan. Read it in: CatalàCastellano
Definition

XMPP (Extensible Messaging and Presence Protocol) is a standard and open protocol that is based on the exchange of XML messages. Initially it was conceived to implement instant messaging (IM) networks but nowadays it's used for a much wider range of features. Any application that needs a messaging system between different distributed modules is a candidate for using XMPP to exchange messages using this technology as middleware. Maybe the best known tools that use XMPP as middleware are Jabber, GTalk and the video conferencing and audio conferencing features of Google itself.
The features the protocol offers us are really broad and powerful:
- Redundancy
- Scalability
- No VPNs are needed to access the services inside a network with NAT
- SSL and Certificates support
- Backends where users are stored: MySQL, LDAP, etc.
- Extensible (it uses what are called XEP)
- BOSH allows using XMPP over HTTP, which by design of the XMPP protocol would be a problem.
Glossary
- JID: the nodes of an XMPP network are identified through this identifier, which has the form: user@domain/resource (example: miquel@servidor.cat/im). Handling of JIDs:
- user@example.com - known as JID
- user@example.com/desktop - known as JID or full JID
- Stanza: the XML messages that are exchanged between an XMPP server and a client are called Stanzas. There are three types of stanzas:
- Messages: they transport information between nodes, the messages can be organised in threads. There are different types:
- normal
- chat
- groupchat
- headline
- error
- Presence: they serve to report the availability of a resource (online/offline):
- away
- do not disturb
- extended away
- free for chat
- IQ Stanza (info query): similar to an HTTP GET/POST/PUT, it serves to ask a node for specific information. Ideal for extending the protocol. For example, IQs are used to know which resources (users) are connected to a chat channel. There are three types:
- get: they request information (HTTP GET)
- set: they provide information (HTTP POST/PUT)
- result: they return the requested information or confirm that a 'set' command has been accepted.
- Messages: they transport information between nodes, the messages can be organised in threads. There are different types:
- Extensibility: in order for extending the protocol to be simple, stanzas support namespaces and any XML element of a stanza can be used as a payload, to transport: XHTML tags, Atom feeds, XML-RPCs, etc.
- Roster: list of people taking part in an event.
- Presence subscriptions: the resources of a network (often the users) can subscribe to other resources (other users) in order to know whether or not they are available at each moment.
- Asynchronism: the beauty of XMPP compared to other protocols like HTTP is that it's an asynchronous protocol, that is, connections are established for a long time and at any moment the server and/or the client can send and receive stanzas through that channel. HTTP protocols establish relatively short connections where often there's only a request and a response and then the connection is closed.
Polling vs PubSub
This is the great paradigm of current client server structures, often the servers have information that is for their clients. But by design the servers can't connect with their clients and have to wait for them to connect in order to give them the information they need. This gives rise to what we know as
polling
, that is, the clients periodically have to go connecting to the servers to find out if they have something new for them. A good example to understand this is
POP3
servers, the servers have a series of emails stored waiting for the clients, through their
MUA
, to connect to download the mail.
Well then in an XMPP network, the clients are connected to the server at all times and have an established permanent channel (real or virtual) between clients and servers. Therefore, the exchange of information is bidirectional and either of the two parties can send and receive
stanzas
without having to establish a new channel, instead they take advantage of the one they already have.
PubSub
is the capability that XMPP resources (XMPP clients) have to subscribe to and publish any information, the possibility of subscribing to a piece of information means that every time the server has information of that type it will send it directly to the client without the client having to ask for it. An example to better understand
PubSub
would be what users do when joining a chat channel; that is, they tell the server that they want to receive any information published on the channel and the server, when some user publishes new information on the channel, sends it automatically to the rest of the users.
As is easy to imagine XMPP gives us a series of advantages for a whole series of applications that other protocols can't, maybe the most powerful one is the one dealt with here. Taking a look at the pros and cons:
Pros (PubSub > Polling)
- Bidirectional exchange of information, there's no need to establish VPNs or other similar systems for there to be transparent access between servers and clients.
- Optimisation of the channel, bandwidth isn't wasted asking questions to find out if there's something new, we directly receive the news.
Cons (PubSub < Polling)
- The channel has to be kept established, in a real or virtual way, that isn't always possible or simple. That's why techniques/protocols like BOSH appear to allow it.
- XMPP isn't optimised for exchanging large volumes of information.
The best known extension: Jingle
It's an extension of XMPP that allows sending signalling messages between resources (clients) of interactive multimedia applications such as voice or video. It was designed by Google and the XMPP Standards Foundation. The multimedia content is sent through RTP(Real-time Transport Protocol) with ICE(Interactive Connectivity Establishment) in order to be able to cross the NAT(Network Address Translation).
Sources
Wikipedia:
Web:
Presentation:
- XMPP 101 - FOSDEM (Free and Open Source Software Developers' European Meeting)