I wanted to develop an XMPP client as a part of some Android app which needs messaging capability, various XMPP servers are available for free download. I chose Ejabberd 2.1.11 because it has a windows version. I installed it, created a server named 'xmpp-server' and 'admin' user. We can start the server by double clicking the start-ejabberd icon created on desktop. It pops up a web page with a link for admin interface where we can manage the server and do stuff like creating more users etc.
I found this link very useful to develop the android app and it also provides the source code for an app named XMPPClient. I downloaded it and tried to run it. It was developed in IntelliJ, I just imported it in Eclipse and made changes where needed. I USB connected my Samsung Galaxy 3 and ran the app from eclipse directly into my mobile.
The XMPPClient app worked perfectly, I was able to log-in (with gmail credentials) using the details provided in the screen shots in that link. I was able to send and receive messages to another google account by providing another gmail address. But my goal was to use my own XMPP server instead of gmail server. So while creating ConnectionConfiguration, I used my IP address for HOST, the port will remain same as 5222 and the service has to be modified to the XMPP server instance I created while installation (xmpp-server in my case).
ConnectionConfiguration conConfig = new ConnectionConfiguration(host, Integer.parseInt(port), service);
Both of my android device & laptop where XMPP server is running are connected to my WIFI network, so I used my LOCAL WiFi IP address of my laptop as host (make sure the XMPP server is up and running). The XMPPClient app in the above link aims to connect to gmail server so it uses smack.jar, whereas in our case we are trying to connect to an XMPP server from Android, so we have to use ASmack jar instead of Smack jar which can be downloaded here. Make sure you add the ASmack jar in lib folder of the app, add it to build path and remove smack jar.
In case if you want to use your external IP address which we can find by simply searching for IP address in google, we will have to make sure that we forward all XMPP requests received by our router to the computer where XMPP server is installed. We can achieve this with simple configurations on the router. Firstly make sure that your computer receives a static IP address (not dynamic) assigned by the router internally. We can do that by visiting the LAN setup on your router configuration link, there simply specify a allowed unused local IP address and hook it with your mac address. It should look something like the following image.
Secondly ask the router to forward the XMPP requests to your static IP (your computer) address when ever it receives a request on its 5222 port, which you can do by visiting virtual servers configurations in the Firewall settings of your router, which should look like the image below.
The updated app worked perfectly well for me. I was able to connect to my XMPP server and successfully logged in as admin & as other users too. I was able to send/ receive messages to another XMPP client. We can create more users using the XMPP admin interface, login to the server by installing app in other android devices to test it. Or we may use any XMPP client like pidgin (available for windows here), login as some user and send messages to the admin. You will be able to send & receive messages using the XMPPClient android app to Pidgin. I tested the app installing on two different android devices, was able to login as different users and was able to send/ receive messages between the two devices. Make sure the computer where XMPP server is running and the android devices are all using the same Wi-Fi network if you are working with Local IP address else if working with external IP address you may be on any network. Also make sure the recipient id should be mentioned as userID@XMPPServerInstanceName, in my case it would be hari@xmpp-server.
In case if you want to use your external IP address which we can find by simply searching for IP address in google, we will have to make sure that we forward all XMPP requests received by our router to the computer where XMPP server is installed. We can achieve this with simple configurations on the router. Firstly make sure that your computer receives a static IP address (not dynamic) assigned by the router internally. We can do that by visiting the LAN setup on your router configuration link, there simply specify a allowed unused local IP address and hook it with your mac address. It should look something like the following image.
Secondly ask the router to forward the XMPP requests to your static IP (your computer) address when ever it receives a request on its 5222 port, which you can do by visiting virtual servers configurations in the Firewall settings of your router, which should look like the image below.
The updated app worked perfectly well for me. I was able to connect to my XMPP server and successfully logged in as admin & as other users too. I was able to send/ receive messages to another XMPP client. We can create more users using the XMPP admin interface, login to the server by installing app in other android devices to test it. Or we may use any XMPP client like pidgin (available for windows here), login as some user and send messages to the admin. You will be able to send & receive messages using the XMPPClient android app to Pidgin. I tested the app installing on two different android devices, was able to login as different users and was able to send/ receive messages between the two devices. Make sure the computer where XMPP server is running and the android devices are all using the same Wi-Fi network if you are working with Local IP address else if working with external IP address you may be on any network. Also make sure the recipient id should be mentioned as userID@XMPPServerInstanceName, in my case it would be hari@xmpp-server.
If you did everything correctly and still not able to connect to locally installed XMPP server using local/ external IP, you should probably check your Firewall settings which should be enabled to receive requests. On Windows make sure you turn on Network Discovery, try to troubleshoot Incoming Connections (image below) and allow to receive requests on erl.
I made lot of changes to the app and published it on the Google Play. I plan to make even more changes to it in near future. You may install it for free on any android device at this link.
The complete source code for the app (Eclipse project) is available on GitHub at this link. Feel free to download. Contributions are welcomed.
If you find any of this useful, feel free to share the blog post on twitter, G+ etc and rate the android app :)


