What is XMPP
XMPP stands for
Extensible Messaging and Presence Protocol. It's a mature and a well-defined protocol.
xmpp enables the near-real-time exchange of structured xml data between two or more network entities. But it's designed for small chuks or data, rather thand large blobs or binary data.
Main Components of XMPP
The XMPP protocol can be divided in to two parts, Core and Extensible part. XMPP core serveice provides one to one messaging capabilities, user Presence, contactlist and security mechanisms for communication beetween two parties.
XMPP Extensible part provides additional sevices such as multi user chat, service discovery services.
How does Xmpp Communication Work
XMPP is based on the client serve architecture. It can provide the means of communication between client to server or server to server. There are many XMPP servers on the internet and those are interconnected with federated networks. Each an every client who is connected to an XMPP server is assigned a unique identifier with the following format.
where, user is username domain.com is domain that used to reach to the node. This identifier is called jabber id. When client a starts a session with XMPP server, the client opens a long lived tcp connection with server and starts an XML stream to the server. When the server accepts it, server also opens an XML stream to the client. Therefore there are two xml streams. One from client to server and the other one from server to client.
The most basic unit of communication in XMPP is called a stanza. there are 3 type of stanzas used in xmpp.
Presence stanza is used to share Presence information between a client and the contacts of the clints (roaster).
<Presence from="email@example.com" id="1232312312312" to="firstname.lastname@example.org" > <show>online</show> </Presence>
The stanza type
Message is used to share chat messages between two parties.
<message from="email@example.com" id="1232312312312" to="firstname.lastname@example.org" type="chat" > <body>Hi friends</body> </message>
IQ is used to share information between XMPP server and the client.
Sample IQ request
<iq id="1952c42c-8fbf-43d6-9b85-5b0e79c3e3f7:sendIQ" to="email@example.com" type="get" xmlns="jabber:client"> <vCard xmlns="vcard-temp"/> </iq>
Sample IQ response
<iq type="result" id="1952c42c-8fbf-43d6-9b85-5b0e79c3e3f7:sendIQ" from="firstname.lastname@example.org" to="email@example.com/converse.js-132196857" xmlns="jabber:client"><vCard xmlns="vcard-temp"> <FN>Nifro</FN> <NICKNAME>Akalana</NICKNAME> <URL/> <ROLE>Dev</ROLE> <EMAIL><INTERNET/><PREF/><USERID>firstname.lastname@example.org</USERID></EMAIL> <PHOTO> <TYPE>image/png</TYPE> <BINVAL>iVBORw0KGgoAAAANSUhEU</BINVAL> </PHOTO> </vCard></iq>
xmlns attribute describs wheather the client is requesting data from the server or sending data to the serve. For example, if the client wants to get his contact list, he will use xmlns “jabber:iq:roster”
Popular XMPP Servers and Clients
Here are three popular XMPP servers.