Instant Messaging in Android using XMPP(Openfire)

Published On: 23 January 2017.By .
  • Mobile
  • Product & platform Engineering

Extensible Messaging and Presence Protocol (XMPP) is a communications protocol for message-oriented middleware based on XML (Extensible Markup Language).[1] It enables the near-real-time exchange of structured yet extensible data between any two or more network entities.

In this blog, we are taken Openfire server. Read more about Openfire here We divided in following part.

  • Download Openfire
  • Install Openfire
  • Create a new Project and add dependency in build.gradle
  • Create Chat Manager class
  • Setup with Smack service


Download Openfire- Download Openfire from here

Install Openfire- You need to follow few step for setup –

Add dependency in build.gradle- Add the following dependency in build.gradle

Build Chat Manager- 

Create Connection-

Add Connection Listener –

XmppConnection definition is –

Setup Packet Reply Timeout- 

Add Reconnect Manager with Connection

Add Ping Manager– Ping manager is ping to a server in fixed interval. If server replies as pong then the client is can communicate with a server. Other call callback onPingFalied method call

Add Stanza(Packet) listener with Connection- 

Add Stanza (Packet) acknowledgment listener-   

Connect with Openfire –

Login in Openfire – 

Add Delivery Receipt with Message  

Disconnect  with server 

Send One to One Message

Chat Message definition


Now your complete code look like below code


 Background Service that makes Connection alive. 


  • Next step Code 

Related content

Got an Idea?

Let’s create a better tomorrow together