XMPP BASICS : part 1

  • XMPP ( Extensible Messaging and Presence Protocol )
  • It is a Real time communication protocol.
  • The first IM service based on XMPP was Jabber.org
  • One XMPP binding is BOSH. Others include TCP and WebSocket.
  • BOSH is “Bidirectional-streams Over Synchronous HTTP”, a technology for two-way communication over the Hypertext Transfer Protocol (HTTP).
  • BOSH emulates many of the transport primitives that are familiar from the Transmission Control Protocol (TCP). For applications that require both “push” and “pull” communications, BOSH is significantly more bandwidth-efficient and responsive than most other bidirectional HTTP-based transport protocols and the techniques known as AJAX.
  • BOSH achieves this efficiency and low latency by long polling.

Explanation:

NORMAL POLLING:

Normal Polling

Conventional chat apps uses normal polling. Here the top of the graph  indicates client side. Bottom indicates server side. Let the timeout be 5 min.

Client asks the server : ” Is there any new message for me ?

 

Server Responds : “No ! ”

After 5 min

Client asks the server : ” Is there any new message for me ?

 

Server Responds : “No !”

After 1 min

Client Receives a message

After 4 min

Client asks the server : ” Is there any new message for me ?

 

Server Responds : “Yes! ” + message.

You can clearly see that, Client has to wait for another 4 minutes, to get the message. This increases latency.

LONG POLLING:

XMPP Polling

The top part of the graph is client . Bottom part is server.

Client asks the server : ” Is there any new message for me ?

 

Server Answers : “No ! But you may soon receive a new message, so let me just hold your client state for 5 min in the server.”

 

After 5 min

Server Responds : “No !”

 

Client asks the server : ” Is there any new message for me ?

 

Server Answers : “No ! But you may soon receive a new message, so let me just hold your client state for 5 min in the server.”

 

After 1 min

Client Receives a message

Server Responds : “Yes! ” + message.

You can see clearly, how instantaneously the communication happens.

  • XML stream acts as an envelope for all the XML stanzas sent during a session.  (Basically, all the datas are send in XML)
  • XML stanzas can be categorized into 3 : <message> , <presence>, <iq>
    XMPP XML Stanzas
  • <iq> stands for information query. ( Used mainly for getting users friend list etc. )
  • <message> handles the message flow between users.
  • <presence> handles user presence. ie status, online or not etc.

Please read my tutorial series on how to make an XMPP client in Ionic Cordova (Hybrid Platform)

XMPP chat in Ionic Cordova (Setting chat server in local host): Part 2

Ionic XMPP chat Client using Strophe.js: Part 3