How to Use Ejabberd & Erlang to Develop a 1-1 Chat App From Scratch?
Chat apps have been revolutionizing the apps market. Thus, its essence in industrial and versatile communication is significant. To create some exposure within the enterprises and business professionals who wish to create a chat application using some of the high-grade technologies, here comes the enlightenment. Well! In this article, I will walk through the end-to-end development of a chat application from scratch. The technologies are the key factors used for WhatsApp success. So, we would be handling with such technologies Erlang (Language), Ejabberd (Framework), XMPP Protocol, MySQL (Database).
Here comes a list of technical procedures parameters you will be following to develop one-to-one chat application.
- Erlang
- MySQL
- Ejabberd
- PSI+
- One to one chat
Install and Setup Erlang On Ubuntu
Erlang is an open source functional programming language used in generating high scalability and requirement of system availability. It's a concept of “Write once and Run forever”. It’s a collection of libraries and design principles that are written in Erlang language which helps to run a high run-time application with high scalability.
Here comes the installation procedure of Erlang in Ubuntu Server:
Step 1: Download the Erlang in the Ubuntu Server
In Linux server, download Erlang version of 18.0 from the source file using the given link. The version update is expected to extend regularly.
Thewgetcommand is the command used to download the Erlang source file.
$ wget http://erlang.org/download/otp_src_18.0.tar.gz
Step 2: Extract the Erlang tar file
Extract the downloaded tar file using the command given below:
$ tar -xvzf otp_src_18.0.tar.gz
Step 3: Adding dependencies in the command
Ensure to offer the required dependencies through single library function in order to perform certain particular tasks.
$ sudo apt-get install gcc make build-essential libncurses5-dev openssl libssl-dev fop xsltproc unixodbc-dev libwxbase3.0 libwxgtk3.0-dev libqt4-opengl-dev autoconf
Step 4: Begin the compilation and Install the Erlang
In order to compile the source code, it is advisable to use the “make” command to execute the file. Install the Erlang version using “make install” command on the Linux server. To verify the dependencies, go with “Configure” command.
$ sudo ./configure
$ sudo make
$ sudo make install
Install MySQL and Import Ejabberd DB
Install the updated version of MySQL database with the help of given below command:
$ sudo apt-get install mysql-server-5.6
-
On the installation of MySQL server package, a dialogue screen losetupthe MySQL root password screen will open on the terminal. Enter your MySQL user root password.
-
Enter the confirmation on the popup menu.
-
Once the installation of MySQL server, the server runs automatically with the appropriate user and password which is defined earlier.
-
Use the given command to login into the MySQL server with the required MySQL root password set while the server installation.
Run the following link to run and understand the status of the MySQL server.
$ sudo service mysql status
- Use the following command to create the server database
$ mysql -u root -p
- Here opens popup menus following to enter the password and create the database for one-to-one chat
$ mysql> create database chat;
$ mysql > \q;
- Copy the entire Ejabberd MySQL database structure from the link to save it in the mysql.sql file.
https://github.com/processone/ejabberd/blob/16.08/sql/mysql.sql
- Import the entire Ejabberd database structure to chat database
$ mysql -u root -p chat < mysql.sql
Install Ejabberd XMPP Server on Ubuntu
As we know Ejabberd is an XMPP programming server which is written using the Erlang programming language and remains as one of the most used open source platforms by developers. Ejabberd simply runs on a diverse number of operating systems namely Mac, Linux, Windows, Unix etc. XMPP stands as the typical backbone of the chat app in enabling the user to send real-time messages on the go. The protocol also offers features such as Online presence indicator, XML routing and so on.
The Installation process of Ejabberd XMPP server on Ubuntu 14.04/16.04:
Step 1: Download the Ejabberd server from Ubuntu terminal
Download the ejabberd source file in the Linux server with the help of the given link. The Ejabberd version 16.08 is being used which may also extend in the regular updation. Wget command is used to download the Erlang source file.
$wget https://www.processone.net/downloads/ejabberd/16.08/ejabberd-16.08.tgz
Step 2: Extract the Erlang tar file
Extract the downloaded tar file using the command given below:
$ tar -xvzf ejabberd-16.08.tgz
Step 3: Adding Dependencies in the command
Ensure to offer the required dependencies through single library function in order to perform certain particular tasks.
$ sudo apt-get install rebar libyaml-dev libexpat1-dev
Step 4: Verification of the issues
Autogen.sh is the command used to validate, compile and verify the functionality in order to overcome the initial issues.
$ ./autogen
Step 5: Begin the compilation and Install the Erlang
In order to compile the source code, it is advisable to use the “make” command to execute the file. Install the Erlang version using “make install” command on the Linux server. To verify the dependencies, go with “Configure” command.
$ sudo ./configure
$ sudo make
$ sudo make install
Step 6: Open the Ejabberd configuration file
Open it through the command and set the database
$ sudo nano /etc/ejabberd/ejabberd.yml
Enter the the necessary details such as Database name, username, and password to confirm.
auth_method: sql
sql_type: mysql
sql_server: “localhost″ (Mysql Database IP)
sql_database: “chat” (Database name)
sql_username: “root” (Database user name)
sql_password: “password” (Database password)
Finally, save the file /etc/ejabberd/ejabberd.yml
Step 7: Run the Ejabberd server
Run the ejabberd server to refresh the database once the entire changes have been made.
$ sudo ejabberdctl start
Step 8: Check the status of the process using local host
Use the given command to verify the ejabberd installation
$ sudo ejabberdctl status
Now the ejabberd at local host starts with the command and shows the ejabberd running at 0.0.
The browser displays the text which is similar to the XML using the localhost IP “http://localhost:5222”
<!--?xml version=’1.0'?-->
Register the users in Ejabberd with the help of given code.
$ ejabberdctl register user1 localhost password
$ ejabberdctl register user2 localhost password
Installation of PSi+ Software for One-to-one Chat
Download & install the PSi+ Software through Ubuntu Software Centre.
The following procedure and Screenshots can be followed to register the user and create a 1-1 chat app.
- Click on the indicated icon for a setting of account “User1”.
- Move to Account Setup to validate the “User1” and Follow with “add button”.
- In the respective dialogue box enter the XMPP address as “user1@localhost” or server IP and Password on the dialogue box.
- Close the dialogue box to blank the personal information of the user.
-
Follow up the steps given from 1 to 3 in order to register the “User2”
-
To enable the “Online” status, click on the online icon on right for both the users.
- Enter the XMPP address as “User” i.e (User1@localhost) to add the contact in the “User2”.
- Follow the screenshot guidance to add “User2” in the list “User1”.
- Close the dialogue screen by clicking on “add/auth”.
- Make sure to double click on the “User1” to enter the messaging to get received by the “User2” in the following popup screen.
The same process can be followed for “User2”.
- In order to obtain the XMPP protocol format, right click on “User1” and follow the process - Account -> XML console -> Enable & Filter option.
So, now you are done with the entire process to build chat app and 1-1 chat functionality using Ejabberd and Erlang. Hope you enjoyed the insightful process in building a chat app for mobile using ejabberd. If you face any trouble or build a sublime chat app, get in touch with me.