Let me first introduce you with the Chat Client Application for iPhone.
What exactly this is all about?
Ans: This chat application is just like your yahoo messenger, Skype or Gtalk, and the same functionality will be there in this chat client.
What is used to develop this application?
And: This application needs a Mac OS X, with Xcode installed, and main importantly let me tell you at first note that this will be built on ARC in xcode. This application is based on the XMPP Protocol.
What is ARC in Xcode?
And: ARC is Automatic reference counting. This means that the Xcode is now able to release the memory automatically, so you will not be able to use the “release”, “dealloc” functions in this project.
XMPP stands for eXtensible Messaging and Presence Protocol. Such a protocol is open-standard and oriented to message exchange. You can find more about the XMPP on www.xmpp.org and the library is being developed by the Robbie on Github all credits goes to him.
How Does it Work?
The XMPP protocol is based on XML (Extensible Markup Language) so each type of message (e.g. login, message send, etc.) is encoded in this format. For example, let’s suppose President Obama sends a message to Hillary. The format of the message would be something like this:
For sake of completeness we should mention that XMPP is a decentralized service, much like email. This means that the Hillary and Obama accounts might be on different servers (i.e. firstname.lastname@example.org and email@example.com). The message is delivered anyway because XMPP enables server-to-server communication. In case Hillary is offline, the message is cached on the server and delivered when she goes online. To keep things simple and focus on the client side, in this tutorial we will consider a scenario with just one server.
Now Lets divide this Xcode project into 4 parts for our understanding.
1. Making a Local Server.
2. Setting up your UI
4. Enhancing it with some emoticons
Lets begin with making you computer as a local server for this iOS Chat client application.
1. Goahead and download the ejabberd server from http://www.process-one.net/en/ejabberd/downloads.
2. Once you download that install it to your MAC or Microsoft XP, so in this tutorial we have used the EJabbered 2.1.8 or you can use the higher one.
Once you complete the download, install it and check that you have the folders that are shown in the below image:
Now, lets go ahead and open the terminal of your Mac.
Now type the following command
X is nothing but whatever version you have downloaded it from the ejabberd website.
now you are in the bin folder now write this command.
you will be listed with the files and folders in that bin folder. So, if you look closely there will be start and stop files.
3. The most important commands are ‘start’ and ‘stop’. In case they are not executable you can make them so by issuing the following shell command:
chmod 755 stop
chmod 755 start
The folder also contacts the postinstall.sh so you have to write the following command in your terminal window
./postinstall yourname server.local serverpassword
yourname = Your server admin name
serverpassword = your server password
We have selected the server.local, the name of the local machine, as domain but ‘localhost’ would work as well.
So now to start the server you have to write the command that is ./start
4. Once you write this command and hit enter you will be redirected to the ejabberd webpage just like this.
So this tells us that your server is now started. And if you see “ejabbed service logs” then you will be able to see the logs that shows that you are connected to the local server and how it got connected.
5. Now login into your server with the details provided on this page itself.
At the moment our service has just administrators. We need to populate it with at least one user. The previous web page contains a link to the admin interface, which is available at http://localhost:5280/admin/. Once you have logged in as the admin you should see a console like the following
6. We click on the “Access Control Lists” item and the list of currently registered users appears. We create a new user, named ‘anyname’, by entering its details and clicking submit
Now let’s test the server
Now we are able to test the server and check that it works correctly. To test it we can run two desktop applications which support the XMPP protocol. One is iChat, which comes with Mac OS X. You can find another, the one that suits you better, from this list:
In our case we will use Adium, which is available here. We will configure an account for ‘name’ on iChat and another for ‘sample’ on Adium. Let’s start with iChat. Start the application and open the Preferences menu and select the Accounts tab.
Once you are connected you can change your status by means of the drop down menu at the top of the window. Let’s set it to online. Now let’s move to Adium. We start the application and we open the Preferences menu. Adding a new account is pretty similar to iChat. Here we enter the ‘Jawad’ details.
In this case we have also to specify the server which is running jabber. We select the ‘Options’ tab and we fill it as follows
Adium will ask you to accept the certificate as well. Now we have to two users connected to the server by means of two different applications. This should also be reflected in the log file of ejabbered. The file is located at: ‘/Applications/ejabberd-2.1.8/logs/ejabberd.log’ and should contain the following messages
If you remember I have shown you the link above, to see the logs.
In the log you will see like this
for example : There will be text like
Accepted Authentication for jawad by ejabberd_auth_internal
Opened session for firstname.lastname@example.org/sme
Accepted authentication for otheruser by ejabberd_auth_internal
Opened session for email@example.com/sme
Chatting is about friendship. Although both users are connected to the server their are not enabled to chat unless they add once each other as friends. The scenario will be the following: jawad adds otheruser to his list. In the iChat window we select the “+” button at the bottom.
and we enter the jabber id ‘firstname.lastname@example.org’
On Adium we should receive an Authorization Request as follows
Once otheruser accepts it we should end up as in the following figure, jawad is friend with otheruser (and vice versa) and both can exchange messages.
We have tested all the functionalities needed for the server:
- Login with username and password
- buddy list
- chat messages exachange
This was needed to ensure that possible errors in the iOS application are not due to server misconfigurations. Now we are ready to dig into the development of the iOS application.
So, guys click on the next page for the continuation of this tutorial.