Extensible Messaging and Presence Protocol (XMPP) is a communications protocol for message-oriented middleware based on XML (Extensible Markup Language). It enables the near-real-time exchange of structured yet extensible data between any two or more network entities.
How the Whatapp Works!
WhatsApp is a real-time messaging application, which makes use of Ejabberd (XMPP) server. This server facilitates instant message transfer between two or many users at any given second.
ERLANG is the programming language used by WhatsApp. Ejabberd is an open source Jabber server written in Erlang language. It was preferred by the techies of WhatsApp as it was suitable for accommodating huge communication system with high sustainability.
Building a chat application
- Openfire server installation (XMPP SERVER)
- Openfire server configuration
- XMPP IM android client
Openfire server installation (XMPP SERVER)
The server we will use is Openfire, a real-time-collaboration (RTC) server provided by Ignite Realtime under the Open Source GPL. The protocol that Openfire uses is Extensible Messaging and Presence Protocol (XMPP), also known as Jabber. Actually, Google Talk uses XMPP for its instant messaging function.
Download the Latest build of Openfire from here
Openfire is a Java based server and does not require administrator privileges in order to start. The .tar.gz build does not contain a bundled Java runtime (JRE). Therefore, a JDK or JRE 1.5.0 (Java 5) or later has to be installed on your system. If not, follow one of the countless online tutorials on how to install it. Note that Java can also be installed without administrator privileges.
follow the commands in terminal:
- tar -xvzf openfire_3_6_4.tar.gz
- cd openfire/bin/
- chmod +x openfire
- ./openfire status
- ./openfire start
You will receive the following response:
nohup: appending output to `nohup.out’
The server binds to port 9090 by default. So let’s visit the administration console by visiting the following URL (“localhost” is the linux machine hostname):
If everything worked, you should see the following screen:
Choose your language (I will go with English) and hit “Continue”. In the following screen, the server settings are configured.
The “Domain” option should be automatically populated. Choose the ports for Admin Console. Actually, the default options should be just fine.
Next step is to configure the database settings. Openfire can use various external databases, but also an embedded one.
For reasons of simplicity, I chose to go with the embedded HSQLDB option, but if you wish to connect with another database, there is a guide in the file “documentation/database.html”. Note that HQSLDB will use a folder named “embedded-db”, so make sure this does not get deleted.
Next we have to complete the profile settings
That’s it. If the installation was successful.
The first login attempt fails. You need to restart the Openfire server!
So, first stop the server:
- ./openfire stop
and then start it again:
- ./openfire start
Browse again to the admin console page (http://localhost:9090/) and login to your account.
Openfire server configuration
Login to the admin console and choose “Users/Groups”. There you should see the existing users under “User Summary”. Only “admin” is currently existent, so choose “Create New User” from the left panel.
Fill in the user’s information as shown above and make sure the “Is Administrator” option is not selected. Hit the “Create & Create Another” button to create the current user and repeat the procedure to create a second one. I created users “testuser1” and “testuser2”.
Now let’s use an XMPP client to actually connect to the server. You can try the webclient for xmpp from here
XMPP IM android client
We can you the above xmpp server to build the android client. Or you can use any xmpp client also with the above server. Here am giving two xmpp client which is working perfectly fine.
Then open your andorid studio.
- import the client app to the studio
- then configure the xmpp server with the client
- Create a connection to the igniterealtime.org XMPP server.
- XMPPConnection connection = new XMPPConnection(“myxmppserver.com”);
- Connect to the server connection.connect();
- Most servers require you to login before performing other tasks.
- connection.login(“myuser”, “mypass”);
- the build and run the project
- make sure that the android phones you are using are on same network to access the xmpp server
You can enable the media sending feature in the xmpp server for sending media files over the client, and you can add more plugin to the server based on the requirement