Building a Jabber Client for iOS: Server Setup

In this tutorial we will build a Jabber Client for iOS. The application developed in this series will enable users to sign in, add buddies, and send messages. In the process of building this app, we will describe how to install and configure a jabber server, create accounts, and interact with the server from an iOS application. To simulate a chat environment we will build a scenario with two users: one user will be chatting from an iPhone app and the other will be using iChat.

What is Jabber?

Jabber is not a tool but a community which builds and maintains XMPP. XMPP stands for eXtensible Messaging and Presence Protocol. Such a protocol is open-standard and oriented to message exchange. The original name of the protocol was Jabber, so the terms are often used interchangeably. Message exchange happens near real time, so it is an ideal infrastructure to build chat-like applications. The protocol also implements a mechanism to notify presence information (whether a user is online or not) and the maintenance of a contact list. XMPP is a thorough protocol, which has been adopted also by big companies like Google to build their Instant Messaging service.

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:

<message type="chat" from="obama@server.com" to="hillary@server.com">
	<body>Hi there</body>
</message>

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. obama@server.com and hillary@otherserver.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.

Installing Jabber

There are many implementations of Jabber servers. A pretty complete list is available here: Xmpp. In this tutorial we will use jeabbered for it is easy to install and configure. Ejabbered is developed in Erlang, it is opensource and can work on many operating systems, including Mac OS X. The choice of such an implementation is also due to the easy web interface, which allows to quickly configure the service and manage user accounts. Ejabbered is available for freehere. We select the Mac OS X version and start the download. In this tutorial we will use the version 2.1.8.

Jabber Client

The installation process is very easy and intuitive. In fact the downloaded file is an application which assists us in the installation process by means of a wizard. Once completed we should have a folder named 'ejabbered-2.1.8' in our 'Applications' directory. The folder should contain the following subfolders.

Jabber Client

The most important folders are 'conf' and 'bin'. The first contains configuration files to administer users' privileges. The second includes commands to manage the server. Let's open a terminal and move to the bin folder. We should see something like this.

Jabber Client

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 contains also a 'postinstall.sh' script, which has to be run right after the installation to create the admin user. The script expects three parameters: user, domain and password. So we can run it like this:

./postinstall.sh cesare jerry.local password

We have chosen jerry.local, the name of the local machine, as domain but 'localhost' would work as well. This starts the server and adds this user as administrator. To double check if the configuration is correct we can open the 'ejabberd.cfg' file in the 'con' folder. In the Access Control List section it should contain the following
statement

 {acl, admin, {user, "cesare", "jerry.local"}}.

Now you should be able to start the jabber server by typing

./start

This will open by default a web page which notifies you that the server has been started.

Jabber Client

Configuring Jabber Users

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

Jabber Client

We click on the "Access Control Lists" item and the list of currently registered users appears. We create a new user, named 'alterego', by entering its details and clicking submit

Jabber Client

Testing 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:

http://xmpp.org/xmpp-software/clients/.

In our case we will use Adium, which is available here. We will configure an account for 'cesare' on iChat and another for 'altergo' on Adium. Let's start with iChat. Start the application and open the Preferences menu and select the Accounts tab.

Jabber Client

The "+" buttons allows adding a new account, which we fill with the following data:

Jabber Client

The first connection might take some time (e.g. 30 seconds). iChat will probably ask you to accept the unknown certificate which is bundled with the server. Just click continue.

Jabber Client

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 'alterego' details.

Jabber Client

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:

Jabber Client

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

Jabber Client

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: cesare adds alterego to his list. In the iChat window we select the "+" button at the bottom.

Jabber Client

and we enter the jabber id 'altergo@jerry.local'

Jabber Client

On Adium we should receive an Authorization Request as follows

Jabber Client

Once alterego accepts it we should end up as in the following figure, cesare is friend with altergo (and vice versa) and both can exchange messages.

Jabber Client

We have tested all the functionalities needed for the server:

  • login
  • buddy list building
  • message exchange

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.

Source Code

The complete source code for this project can be found on GitHub here.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
辽B代驾管理系统对代驾订单管理、用户咨询管理、代驾订单评价管理、代驾订单投诉管理、字典管理、论坛管理、公告管理、新闻信息管理、司机管理、用户管理、管理员管理等进行集中化处理。经过前面自己查阅的网络知识,加上自己在学校课堂上学习的知识,决定开发系统选择小程序模式这种高效率的模式完成系统功能开发。这种模式让操作员基于浏览器的方式进行网站访问,采用的主流的Java语言这种面向对象的语言进行辽B代驾管理系统程序的开发,在数据库的选择上面,选择功能强大的Mysql数据库进行数据的存放操作。辽B代驾管理系统的开发让用户查看代驾订单信息变得容易,让管理员高效管理代驾订单信息。 辽B代驾管理系统具有管理员角色,用户角色,这几个操作权限。 辽B代驾管理系统针对管理员设置的功能有:添加并管理各种类型信息,管理用户账户信息,管理代驾订单信息,管理公告信息等内容。 辽B代驾管理系统针对用户设置的功能有:查看并修改个人信息,查看代驾订单信息,查看公告信息等内容。 辽B代驾管理系统针对管理员设置的功能有:添加并管理各种类型信息,管理用户账户信息,管理代驾订单信息,管理公告信息等内容。 辽B代驾管理系统针对用户设置的功能有:查看并修改个人信息,查看代驾订单信息,查看公告信息等内容。 系统登录功能是程序必不可少的功能,在登录页面必填的数据有两项,一项就是账号,另一项数据就是密码,当管理员正确填写并提交这二者数据之后,管理员就可以进入系统后台功能操作区。项目管理页面提供的功能操作有:查看代驾订单,删除代驾订单操作,新增代驾订单操作,修改代驾订单操作。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。新闻管理页面,此页面提供给管理员的功能有:新增新闻,修改新闻,删除新闻。新闻类型管理页面,此页面提供给管理员的功能有:新增新闻类型,修改新闻类型,删除新闻类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值