ejabberd using amazon ec2 (AWS) and XML RPC for android xmpp chat Part -1

If you want Setup a Android / Web based Chat Client using XMPP then you can use Ejabberd (XMPP) server. and a Instance of Amazon AWS ec2 Instnace.     

ChatApp

A Chat Application Server side Prerequisites are show as figure.

Ejabberd (XMPP) server. This server facilitates instant message transfer between two or many users at any given second .

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.

chatusing_xmppExtensible 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.

As and when message is sent, it is queued on the server. The message waits in the queue until the recipient reconnects to receive the message. As and when a message is delivered the sender gets notified by a double check mark near the message. After the delivery the messages are instantly deleted from the server memory.

bla-bla-chat

So, we have leaned about background what are the components are required for setting up xmpp chat application.

First Start lets start with AWS EC2 Instance:

https://aws.amazon.com/free/ check the link where one instance of ubuntu is free in Free Tier, we can get instance of ubuntu using this.

ec2

After you signed in to the AWS Console you can launch a instance in Free Tier and start configuring it.

free

    After you select you can launch the instance and start getting access for the same to login to the instance we need to have Putty and PPK file which authorizes the AWS ubuntu instance.

Create a Keypair for the instance and download the PPK file check the link:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html

http://docs.aws.amazon.com/gettingstarted/latest/wah-linux/getting-started-deploy-app.html

Now we are ready to configure the ubuntu as Ejabbed Server.

Lets start with installation and configuration of the  ejabberd.

login to your instance via SSH putty execute these commands.

apt-get -y install ejabberd

By default, hostname used by eJabberd is ‘localhost’, which can be modified from config file.

before that create a user new admin or admin :

/etc/init.d/ejabberd restart
ejabberdctl register admin ec2-xxxxxxxxx.us-west-2.compute.amazonaws.com password

For our example we will call our admin user “admin@your_domian_name” and modify the following lines in /etc/ejabberd/ejabberd.cfg:

vi /etc/ejabberd/ejabberd.cfg

modify admin user and domain.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Options which are set by Debconf and managed by ucf

%% Admin user
{acl, admin, {user, "admin", "ec2-xxxxxxxxx.us-west-2.compute.amazonaws.com"}}.

%% Hostname
{hosts, ["xxxxxxxx.us-west-2.compute.amazonaws.com"]}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Restart eJabberd

service ejabberd restart

Now you can navigate to your eJabberd Web Admin interface on  aws url port 5280

http://xxxxxxxx.us-west-2.compute.amazonaws.com:5280/admin

AWS EC2 Security Group & Firewalls

Please ensure that port 5280 is enabled. Below is suggested configuration

Type Protocol Port Range Source
Custom TCP Rule TCP 5280 0.0.0.0

login to the ejabber and add the user.

eJabberdWebLogin

Adding New Users

From web admin interface, click Virtual Hosts ->xxxxxxxx.us-west-2.compute.amazonaws.com-> Users

eJabberdAddUsereJabberdAdmin2

Now How do we test the Jabber Client:

Check https://www.xabber.com/

Install android application : https://play.google.com/store/apps/details?id=com.xabber.android

Screenshot_2015-12-27-16-53-02unnamed

Now you are logged into the Ejabber Server.

In Next We will learn how to Set up XML RPC for the Ejabber and Writing a Android Client for ejabber from the Scratch  See : https://androidtechieblog.wordpress.com/2015/12/27/ejabberd-using-amazon-ec2-aws-and-xml-rpc-for-android-xmpp-chat-part-2/

 

ejabberd using amazon ec2 (AWS) and XML RPC for android xmpp chat Part -1

10 thoughts on “ejabberd using amazon ec2 (AWS) and XML RPC for android xmpp chat Part -1

      1. Roman B says:

        I love your all troubles for this awesome post.
        I hope to keep in touch with you in the future. I am still not clear regarding XMLRPC.
        Looking forward your sincere help Anil.
        Best Regards

        Liked by 1 person

  1. XMLRPC is to communicate between you REST web service Web Application and Ejabberd XMMP Server.
    Consider from your Android application user registration happens , to create a user id i.e ejabber chat id for each user who register XML RPC will help.

    When ever REST API Called from mobile you can write XMLRPC call to create a user in ejabberd.

    hope i am clear with user case , there are lots of use cases using XMLRPC with ejabberd.
    here is code to create jabber id for user from your rest api using xml rpc.

    private void activateJabberAccount(Users user) {
    String Domain = "XXXXXXXXXXXXXXXXXXXXXXXX.compute.amazonaws.com";
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    try {
    config.setServerURL(new URL("http://127.0.0.1:4560/RPC2"));
    } catch (MalformedURLException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    XmlRpcClient client = new XmlRpcClient();
    client.setConfig(config);

    /* Command string */
    String command = "register";

    /* Parameters as struct */
    Map struct = new HashMap();
    struct.put("user", user.getName() + "-" + user.getMobile());
    struct.put("host", Domain);
    struct.put("password", user.getMobile());

    Object[] params = new Object[] { struct };
    try {
    client.execute(command, params);
    } catch (XmlRpcException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }

    Liked by 1 person

    1. Roman B says:

      I have got main point, Thanks so much for your quick update always..
      I also should do my best to help your troubles whatever I could do for you.
      Really helpful for me. I was cracking my head to learn about eJabberd and conceptions about XMPP/eJabberd.
      You solved completely my issues.
      AAAAA+

      Liked by 2 people

  2. Hello Anil,

    this is long time later meeting again 🙂
    I hope you are doing great there.

    I have one issue with XMPP based chatting.
    I am wondering if XMPP supports sending image/voice messages in multi-user chat.
    could you guide me with this one?

    https://conversations.im/
    I checked out the open source from this site.
    It never supports sending image/voice messages in multi-user chat. (for just one to one its working properly).
    So let me clarify whether XMPP never supports that or Conversations team has never implemented that yet or not.

    Additionally, let me know how I could implement and any tutorial for this if I need to do this myself.
    Thanks,
    Roman

    Like

  3. Thanks for your following me 🙂
    I am happy to connect with you.
    Recently, I was working on the implementation of Group chatting.
    But I had some road blocks regarding voice, image sending in group chatting.

    Looking forward your advise.
    Cheers

    Like

  4. khouloud says:

    Hi,
    Thank you for your helpful tuto
    but i got a problem of dns : ERR_NAME_NOT_RESOLVED
    I checked that the port 5280 is added but always same problem

    Like

Leave a comment