How to Install Openfire XMPP Server and Use it with Smack Android App From Emulator

Openfire is an widely used XMPP Server that is written in the Java programming language. It boastsĀ  an intuitive and easy to use dashboard where your setup is just interacting with the UI and you can get complex setups done very easily. In this tutorial we are focusing on installing Openfire for use with a Smack based Android App on the local machine were Android Studio is installed. It is in response to my students from the course Build an Android Chat App from Scratch using XMPP and Smack, who happen to need this in big numbers. Let’s get started.

Installing Openfire

Openfire and Smack are both developed by an organization called Ignite Realtime, so let’s go to their web page and grab our latest copy of Openfire. Find the Openfire listing and click download for your platform of choice. Being written in Java, Openfire can run on all major desktop platforms : Windows, Mac , Linux. This tutorial is going to be based on Windows, but the same steps should apply to Linux and Mac as well. Start the installer you downloaded and you’ll see a window to let you choose your language

I choose English and move on . Confirm that you want to install the package in the following window :

In the next screens, accept the agreement and chose where you want your packages installed.

Hit next and choose whether you want the shortcuts and the install progress dialog will show up

And when the install is done, you’ll see a confirmation dialog, prompting you to start the Openfire service to start using it right away.

Hit finish and your default browser will open the openfire welcome page where you choose the language of your install.

Choose your preferred language and hit continue. You’ll be given a UI where you should set up your domain name.

Because we want to use our server locally, we set our domain name to be localhost. If we had set it up to be something else, we would have to go mess with the host files to resolve whatever we put in here to a recognizable network address. Just leave in localhost, it is good enough for our local use purposes. Leave the rest to defaults and hit continue. You are then given a choice for the database you want to use.

We choose Embedded database here for convenience, but you can choose Standard Database Connection and set up an external database if you need that. Hit continue and choose a setting for where you want your user info to be saved.

We choose Default in this case. Hit continue, and you are presented a UI where you need to provide server admin info, the email isn’t really important here but you should REMEMBER the password that you put in here .

If you forget the password, you won’t be able to login and see the dashboard for managing your server. Put in your details and hit continue and you’ll see a screen saying that your installation is complete.

Some people haven’t been able to login into the dashboard after a successful install like we have here. An easy fix for that is to stop the openfire service and start it again. Follow the appropriate steps to stop and start openfire on your favorite operating sytem. In this case we are on windows, we are simply going to go in the start menu, find openfire and start a program that allows us to manage it.

Click on the yellow icon that says “Openfire Server” and you are going to see a dialog as shown below

You can see that the openfire service is running. We started it right after our install. Stop it and start it again. and then hit Launch Admin to see the web interface where you can login.

Type in a username of “admin” and the password you specified during  your install. Hit login and you should be in your dashboard.

There is a lot we can do in this dashboard, you can take some time to look around and familiarize yourself with the dashboard if this is your first time with it. For now, click on the Users/Groups tab and hit the create New user button.

Put in the credentials for your user.Remember that because out domain name is “localhost”, our JIDs are going to look like “gakwaya@localhost”. Hit the create user button and you’ll see a screen confirming your success.

We just created one user, but nothing prevents you from creating as many as you want! Openfire is now installed on our local machine. Now we want to use an XMPP Client installed in our virtual device to access it. That’s what we’re doing next.

Communicating from Virtual Device to Host Computer

There is actually an official way to do network communication from Virtual device to Host Computer from the android docs. In the virtual device you push your traffic to an IP address of 10.0.22 and it is forwarded to the address of localhost in the host computer. From our XMPP client, we basically need to specify a HARD CODED host address of This way we can do normal XMPP things with JIDs like “gakwaya@localhost” .

Security : SSL Certificates

Because our server doesn’t have a public facing domain name, and is running locally, we can’t set up an SSL certificate for it. So we will need to disable security when connecting to our server as shown below

.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled) // Should make required on Public Server with SSL Configured

Adapting the Source Code of  your XMPP client

When our XMPP client is talking to our local server, we need to do two things. One is address the XMPP traffic to an IP address of and the other is to use a domain name of “localhost”. That’s what we set up our server to use. We do all that when connecting to the server with the code snippet below :

XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()

        //.setXmppDomain(mServiceName)//Public Internet server
        //.setHost(mServiceName) //Public Internet Server

        .setHostAddress(InetAddress.getByName(""))  //Local Server
        .setXmppDomain(JidCreate.domainBareFrom("localhost"))  //Local Server

Notice that I left in the code you should use when your client is talking to a public server. When you need that,m just comment out the //Local server flagged lines and uncomment the //Public Internet Server ones. You should also note that we have a hard coded XMPP domain because the user doesn’t have the flexibility of using other servers. Switching from local to public is a thing you can control only in code in this case. A screenshot of my setup is shown below in case it helps clarify things.

This should give  you a local environment to test your Smack Android XMPP client against. If you have any questions or queries, please do shoot me in the comments below. I hope this has been informative to you and thanks for reading.

Posted in Servers, xmpp and tagged , , , , , , .

Daniel Gakwaya loves computer Hardware/Software.He is a Software Engineer at BLIKOON and lead developer of bliboard-The whiteboard system currently marketed by the company.He is known to hack around on any piece of tech that happens to pick his interest. More on his tech endeavors here
Follow him on Twitter


  1. Hello I bought your tutorial on udemy and gone through it. I have tried to implement the solution on my local machine using it as the server but it gives the error “Something went wrong while connecting ,make sure the credentials are right and try again”

    • Hi Andrew,
      I don’t have enough info to know what is wrong with your setup but you can try to connect to your server using another xmpp client like Xabber. If you find it cumbersome to install and android client on a virtual device just to test your environment, you can try using a desktop client like gajim ( They all equally work well to make sure your clients can talk to your server. Let me know how it turns out.

  2. Hi, Gakwaya I’m trying to connect to my localhost server but its not connecting, below is the error message

    at android.view.ViewRootImpl.(
    at android.view.WindowManagerGlobal.addView(
    at android.view.WindowManagerImpl.addView(
    at com.blikoon.roosterplus.ChatListActivity.requestBatteryOptimizationsFavor(
    at com.blikoon.roosterplus.ChatListActivity.onCreate(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invoke(Native Method)
    09-03 05:46:31.148 5558-5558/com.blikoon.roosterplus I/AssistStructure: Flattened final assist data: 3496 bytes, containing 1 windows, 12 views
    09-03 05:46:35.856 5558-5558/com.blikoon.roosterplus D/RoosterPlus: saveCredentialsAndLogin() called.
    09-03 05:46:36.543 5558-5558/com.blikoon.roosterplus D/RoosterConService: Service Start() function called. mActive :false
    09-03 05:46:36.545 5558-5558/com.blikoon.roosterplus I/Choreographer: Skipped 40 frames! The application may be doing too much work on its main thread.
    09-03 05:46:36.545 5558-5587/com.blikoon.roosterplus D/RoosterConService: initConnection()
    09-03 05:46:36.554 5558-5587/com.blikoon.roosterplus D/RoosterConnection: RoosterConnection Constructor called.
    09-03 05:46:36.564 5558-5579/com.blikoon.roosterplus I/OpenGLRenderer: Davey! duration=748ms; Flags=1, IntendedVsync=951031575171, Vsync=951064908503, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=951080838100, AnimationStart=951080907200, PerformTraversalsStart=951081557020, DrawStart=951116214810, SyncQueued=951743045040, SyncStart=951745136460, IssueDrawCommandsStart=951745335060, SwapBuffers=951770358490, FrameCompleted=951782197170, DequeueBufferDuration=598000, QueueBufferDuration=1267000,
    09-03 05:46:36.598 5558-5579/com.blikoon.roosterplus I/OpenGLRenderer: Davey! duration=716ms; Flags=0, IntendedVsync=951085986707, Vsync=951752653347, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=951763412130, AnimationStart=951763475950, PerformTraversalsStart=951767307260, DrawStart=951768032220, SyncQueued=951768305590, SyncStart=951782373500, IssueDrawCommandsStart=951782691050, SwapBuffers=951801511200, FrameCompleted=951816324830, DequeueBufferDuration=52000, QueueBufferDuration=240000,
    09-03 05:46:37.191 5558-5587/com.blikoon.roosterplus D/RoosterConnection: Calling connect()
    09-03 05:47:07.193 5558-5588/com.blikoon.roosterplus W/PingManager: XMPPConnection was not authenticated
    09-03 05:47:07.203 5558-5587/com.blikoon.roosterplus D/RoosterConService: Something went wrong while connecting ,make sure the credentials are right and try again
    09-03 05:47:07.205 5558-5558/com.blikoon.roosterplus D/RoosterPlus: Got Connection Error in login activity
    09-03 05:47:07.206 5558-5587/com.blikoon.roosterplus D/RoosterConService: Sent the broadcast for connection Error from service
    09-03 05:47:07.207 5558-5587/com.blikoon.roosterplus D/RoosterConService: Logged in state :falsecalling stopself()
    09-03 05:47:07.216 5558-5587/com.blikoon.roosterplus W/System.err: org.jivesoftware.smack.SmackException$ConnectionException: The following addresses failed: ‘’ failed because: / exception: failed to connect to / (port 5222) from / (port 54330) after 30000ms
    at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectUsingConfiguration(
    at org.jivesoftware.smack.tcp.XMPPTCPConnection.connectInternal(
    at org.jivesoftware.smack.AbstractXMPPConnection.connect(
    at com.blikoon.roosterplus.xmpp.RoosterConnection.connect(
    at com.blikoon.roosterplus.xmpp.RoosterConnectionService.initConnection(
    at com.blikoon.roosterplus.xmpp.RoosterConnectionService.access$100(
    at com.blikoon.roosterplus.xmpp.RoosterConnectionService$
    09-03 05:47:07.306 5558-5558/com.blikoon.roosterplus D/RoosterConService: stop()
    09-03 05:47:07.307 5558-5587/com.blikoon.roosterplus D/RoosterConnection: Disconnecting from server localhost
    09-03 05:47:07.310 5558-5579/com.blikoon.roosterplus D/EGL_emulation: eglMakeCurrent: 0xe0385300: ver 2 0 (tinfo 0xe0383650)
    09-03 05:47:07.337 5558-5579/com.blikoon.roosterplus D/EGL_emulation: eglMakeCurrent: 0xe0385300: ver 2 0 (tinfo 0xe0383650)

    • I would try and connect with a desktop client like gajim( as stated in a previous response and make sure whether the problem is on the server, or the client. Please download gajim ( or any other xmpp desktop client form your host platform) and try to connect with a JID with format ( username@localhost ) , for a user you defined in your Openfire server and use the password you defined there.If that works well , you’ll know the problems is in the android xmpp client, if it doesn’t then it’s the server that is problematic.
      Hope this helps.

  3. thank you very much sir for this wonderful tutorial. i have downloaded and configured my xmpp server with openfire, i have also tested it with gajim and it connected but I’m still unable to send messages from my android app, i am using your code from your first tutorial to connect to my xmpp server but whenever i click on send message button it returns the “Client not connected to server ,Message not sent!” message. please sir i really need your help because i have been stock here for weeks now and i don’t know were else to look.i would really appreciate your help. thanks in advance

  4. Hola amigo buenas tardes disculpe, compre tu curso de XMPP para el envio de archivos por medio del chatt y entre otras cosas. Quisiera hacer mi conexion a openfire segui tus intrucciones pero no hay respuesta alguna no se si me podrias ayudar por favor

  5. Hi, sorry I need your help to be able to make the Xmpp connection with Openfire. I followed the steps you have on your website, but it does not work for me. I do not know if you could help me. The course that you are offering I already have it. But I need to be able to make that connection, I do not know if you have any mail or something to contact me. I would greatly appreciate your help.

      • I could already to connected openfire but i have other problem to transference files. i don’t know if you can help me in this problem. The error is: org.jivesoftware.smack.SmackException: No upload service specified and also none discovered.

        • The error suggests that your server is not configured for http file upload. I believe it’s configurable as a plugin in openfire. Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.