Instant Messaging in Android using XMPP(Openfire)

Published On: 23 January 2017.By .
  • Digital Engineering
  • Mobile

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  http://www.igniterealtime.org/. 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 http://www.igniterealtime.org/downloads/

Install Openfire- You need to follow few step for setup –http://mindbowser.com/openfire-installation-and-database-configuration/

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

That’s all for this blog