Retrospection

Exemplifying the earlier blogs of XMPP we grasped:

1. IM (Instant Messaging) follows a certain protocol, i.e. XMPP
2. XMPP stands for Extensible Messaging and Presence Protocol
3. XMPP is a protocol that transports small amounts of data between two network endpoints.
4. The data exchanged is structured in XML.
5. Data is exchanged via Streams established between the server and client or another server.

Following this the consecutive blog articulated around the 4 Step Life Cycle of an XMPP Connection which included:

• Connection
• Creating Streams
• Authentication
• Disconnection

Stanzas of XMPP Dummies

Moving forward in building our own Chat Application and that the connection has been established, we are now ready to send the messages and start chatting!!

But before we do that, let’s take a deeper look into, “Stanzas” to understand how they make the “chatting” system work.

There are basically three kinds of XML stanzas defined as:

a. <presence> Information related to a user’s presence-online, offline, status messages etc.

b. <message> Actual messages sent between users

c. <iq> Information based on queries

Common attributes in these stanzas are:

1. to
The “to” attribute in a stanza, specifies the recipient of the message or for whom the message is intended. It can be the server itself or another client you would like to chat with. Here we use the “JID” to indicate the recipient of the message.

Let us take the example of a “message” stanza, from the previous post-
       <message from=’abc@example.com’
              to=’xyz@example.com’
                  type=’chat’>
                       <body>We have had a most delightful evening, a most excellent ball.</body>
        </message>

2. from
The “from” attribute, specifies who is the sender of the stanza, or the JID of the origin of the stanza.
For example:

     <message from=’abc@example.com’
            to=’xyz@example.com’
               type=’chat’>
                 <body>We have had a most delightful evening, a most excellent ball.</body>
     </message>

Here, abc@example.com is the sender of the stanza or its origin.
With this we know that stanzas can be sent from both, a client and the server.
The “from” attribute is mandatory when a stanza is sent by a client to their server which when not sent might result in errors. However, many a times, the server also generates stanzas to be sent to the clients, in such conditions i.e. when being sent from a server, one of the following needs to be fulfilled for the “from” attribute-
It should either,
1) not include a ‘from’ attribute or
2) include a ‘from’ attribute whose value is the account’s bare JID or client’s full JID

“Head Scratcher”: Wondering what is Full JID & a bare JID?

In the earlier blog post under subtopic “Authentication”, I spoke about multiple logins from different clients. The differentiation between multiple logins is accomplished via the use of “resources”.
A full JID is a JID that has a resource attached to it, for example your client at home will have a JID as “abc@example.com/home”, and the client in the office will have a JID as “abc@example.com/office”, whereas a bare JID in this case will be, “abc@example.com”.
Hence, using full JIDs one can specify to which client the stanza should be specifically sent.

3. id
It is used for the internal tracking of the “stanzas”, basically for aiding responses. If a stanza is generated in response to a stanza with an id,”xyz”, the response stanza will also have the same id.

4. type
The type attribute has different values, specific to the kind of stanza,
<presence> , <message> , or <iq> stanza. It specifies the purpose of the stanza.

So we have discussed about the common attributes of stanzas in this blog post in detail. Further in our next series we will be discussing more about <presence>, <message> & <iq>.

Related Links for the Blog Post:

XMPP for Dummies- A Beginners Guide to create your own Chat Application
XMPP for Dummies- Part 2- A 4 Step Life Cycle to Create Your Own Chatter!