This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.
Web-based Chat application is the solution to these problems since it does not require any downloading, installation or configuration and besides it is platform independent. This project implements a real time web-based chat application using open ource web application framework Ruby on Rails.
I would like to take this opportunity to remember and acknowledge the guidance, cooperation, goodwill and both moral and technical support, extended by all staff and faculty members of California State University, Sacramento.
I would like to thank my project advisor, Dr. Jinsang Ouyang for supporting the idea of the project and providing me such a great opportunity to work on this project. I am thankful to him because of his continuous guidance on the work performance, motivation and timely suggestions helped me a lot throughout the project.
I am also grateful to my second reader, Dr. Ahmed Salem for being a second reader and providing me great help when needed during the project. He has done great help in giving important advices and proof reading the document.
I am also grateful to Dr. Nikrous Faroughi for helping me during the completion of my project. He has shown the path during preparation for the project and provided great ease during completion of the project.
I sincerely record my debt of gratitude to Dr. Cui Zhang for helping in various prospects and providing enormous guidance during my Masters at California State University, Sacramento.
Finally, I am thankful to my family and friends for encouragement during tough times and guidance during all the time for completion of my Masters project.
With the evolution of the web, demand for web applications to be more interactive and provide live, real time informations to the users has been increasing day by day. Web application is an application that is widely used on Internet. Web application is a computer program that is used with web browser such as Internet Explorer, FireFox, Safari, Google Chrome, etc. Recent web advances in web provide new ways for people to communicate on a global scale and assess vast amount of information. Web application is different from many conventional websites in that their emphasis is on allowing user to accomplish tasks such as send email, make travel reservation, pay bills, instant messaging, etc. Websites on the other hand, are content oriented and are designed to facilitate browsing. Common web application includes e-commerce application like retail sales, trading, online auction and web mails, etc. Today web applications are so widely used in social networking, blogging, instant messaging, etc.
Web application works on hypertext transfer protocol which is a client-server architecture, this means the client initiate the connection and the server only respond to its request. Earlier client-server application had its own client program which served as its user interface and had to be separately installed and configured on each user's computer, instead web application uses standard format document which are supported by browsers. This feature gives more portability as user can access their application from anywhere in the world. Web applications are also popular with business and software developers as they can be developed, maintained and updated remotely.
Figure 1 shows the basic structure of the web applications. 
Figure 1: Basic Architecture of Web Application
In general, web applications use the client/server architecture (i.e. two-tier) where the browser acts as a client. With the evolution of three-tier architecture, it is becoming more popular and even necessary when implementing enterprise systems that require better scalability. Three-tier architecture consist of application server, database Server and client software installed locally (e.g. web browser). Advantage of this system is central database server can be accessed by multiple application server and application server could independently manage thousands of users. Database servers are designed to do database operation such as data storage and low level data manipulation. Application server manages client connections and data processing.
Web-based chat application is a form of web application. It allows users to communicate in very easy way using user-friendly web interface. Using such a web application user can avoid installation of specialized softwares. These applications are also accessible from anywhere, using any browsers and with any operating system. There is no requirement of software installation or any software updates. Web-based chat application requires no application download, updates, installation or configuration. No need for any configuration to avoid firewall since the application is embedded/ integrated in a web browser.
The purpose of this project is to develop a distributed web-based chat application using open source web application framework Ruby on rails and latest technologies like Ajax, Strophe/Jquery and XMPP. There are many web-based chat applications available in the market, but this project explores some exciting features and compatibility of Ajax, XMPP and Strophe/Jquery with latest technology Ruby on rails. This applicaion allows you to chat with your friend or group of friends and navigate some other pages (e.g. Gmail Chat) while instant messaging. This application will let you add your friends, send an instant message, create and join chat rooms, search for chat rooms and saves your recent chat conversations. This application also allows you to send files to your friend or group of friends.
This chapter provides functional overview of the web based application. The goal of this project is to build a chat-application using brand new technologies and allow users to use exciting features of chat and also providing them with features to navigate through other web-pages. This application also provides feature of multi user conference and file transfer.
Interesting Feature of the Application: The users will have following features:
1. Create login password
2. Add New Friends
3. Edit Friends Information
4. Remove friend from the list
5. View the Presence of the friends
6. Change his own Presence Status
7. Send Instance Message to any friend
8. Join any available multi user chat room
9. Create a new multi user chat room
10. Join multiple chat rooms
11. Search for available chat room
12. View the chat Log History
13. Navigate to other pages during instant messaging
14. Tranfer files to your friend
15 Transfer files to group of friends during multi user conference
14. Exit from the Application
The application overview also provides detailed information for the user and system requirements, system models and system evolution of web-based Chat Application. This chat application has three components web-based client, Chat Server and a Web Server. The three components operate together to form web based chat application. Figure 2 shows very basic architecture of Web-based chat.
Figure 2: Basic Architecture of Web-Based Chat
2.1 Web-Based Chat Client
Web based client is an application that transmits messages from user to user. Chat client is an application that communicates with chat server enables users to send messages, to set and change user's presences. Applications can build their own chat client.
2.2 Web Server
Web Servers are the software that allows application to share the information over the internet. Web Servers are based on client-server architecture. Web Servers are the vital part of World Wide Web. e.g. apache. Apache is the most powerful web server used in today's industry.
2.3 Chat Server
Chat server is software that translates all messages for the clients. It also stores all users' contacts and other information collected from outside source. A chat server receives the commands and messages from the chat clients and processes them. It stores user's conversation history as well. Figure 3 shows basic overview of the chat client and chat server.
Figure 3: Basic Chat Application Overview 
The web-based client works as the interface between the user and the server.Â Through the chat client user authenticates to the server using a combination of username and password.Â Once the user is logged on, the user has the option of sending an instant message, creating or joining a chat room, check previous chat history.Â User can also create chat rooms to chat with the multiple user or group of members. Once inside the chat room, the user starts communicating with other users by sending and receiving messages. User can also look for available chat rooms and join them if permitted by the chat room owner. During chat session users are provided with the featue of sending a file to their friends.
TOOLS AND TECHNOLOGY
4.1 Ruby on Rails
Ruby on Rails is an open source web-application framework. Rails is an MVC web framework where models, views, and controllers are fully integrated in a unlined fashion. That means users can have all the benefits of an MVC design without explicitly configuring each component. The Rails framework was extracted from real-world web applications. Ruby on Rails is designed with various component libraries and works in a way similar to any web application framework. In Ruby on rails everything are written in the ruby programming language. Ruby follows strict concepts of Object Oriented programming languages (OOPS). Ruby is a dynamic interpreted language and also used as strong scripting language. 
4.1.1 Instant Rails:
In this project for the development and deployment purpose instant rails is used which contains Ruby, Rails, MySQL and Apache. Instant Rails is the most preferable and easiest way to use Rails on windows machine. Instant rails uses mongrel as secure Ruby/C HTTP server. Mongrel (cluster of Mongrel servers) is used with apache to provide extra speed and ability of configuration. 
Apache is an open source web server developed by Apache software foundation. It is a very complex web server because of the vast number of features provided. In this project with the use of instant rails a mongrel cluster is used, running on top of Apache with load balancing enabled. So a cluster of Mongrel servers is executed locally, and route requests through Apache's mod_proxy_balancer. Apache divides the incoming requests among the available Mongrel processes and with careful configuration it can even serve static content. In this project Apache is configured to forward XMPP request over BOSH by enabling proxy module.
Openfire is an open source XMPP server, written in JAVA language and is both user friendly and easy to install. Openfire administration runs on the ports 9090 (HTTP) and 9091 (HTTPS) by default. Administrators can connect from anywhere and edit the server's settings, add and delete users.  Openfire supports the following features:
Web-based administration panel.
User-friendly web interface and guided installation.
Database connectivity for storing messages and user details.
Lightweight Directory Access Protocol connectivity.
Platform independent, pure Java
In real time web application all the data are real time data, MySQL database server is configured and database is created with Openfire as JDBC driver for MySQL is bundled with Openfire. By using MySQL with Openfire the application can add, edit, delete and query XMPP server users. Openfire stores all data in a back-end database.
MySQL is an Open source database system. It is a relational database management system Â that runs as a server providing multi-user access to a number of databases. It is commonly used for web applications and for embedded applications. MySQLÂ database serverÂ provides scalability and flexibility in supporting platforms. It provides high performance in application and robustness. It also has strong data protection. Instant rails have built in preconfigured MySQL support. 
CSS stands for Cascading Style sheets. It defines how to display HTML elements. Styles are normally saved in external .css files. External style sheets changes the appearance and layout of all the pages in a Web site. CSS can also allows the same markup page to be presented in different styles for different rendering method.
DESIGN AND ARCHITECTURE
Real time web based chat application is designed and implemented using Extensible Messaging and Presence Protocol (XMPP). XMPP is an open source Extensible Markup Language (XML) based protocol for server-to-server communication, instant messaging and presences. For Real time web based chat application XML-based technologies provide significant advantage to web-scale application. XMPP uses Extensible Markup Language as the base format for exchanging information. XMPP specification defines open protocols that are used for communication among networks and real-time interaction over the internet. 
4.1 Basic XMPP Architecture
In XMPP architecture a client with a unique name communicates with another client with a unique name through an associated server. Each client implements the client form of the protocol, where the server provides routing capability. Servers are also used for purpose routing between domains.  Figure 3 shows simple XMPP architecture made up of one server and two clients.
Figure 4: XMPP architecture, consisting of a server and two clients
4.2 Decentralized Architecture
XMPP uses decentralized client-server architecture similar to the architecture used for World Wide Web and email network. This architecture allows one chat client to send messages to any other chat client connected on server. Decentralized architecture based application are easy to manage as client developers can focus on user experience and server developers can focus on reliability and scalability. In XMPP architecture when chat client sends a message to any contact, it first connects to its local server which then connects directly to a contact's server and contact server finally deliver a message to a contact.  Figure 5 shows basic decentralized client-server architecture,
Figure 5: Decentralized Client-Server Architecture
4.3 Jabber ID (JID)
XMPP uses Domain Name System (DNS) to provide the underlying structure for addressing instead of using raw internet protocol addresses. In terms of XMPP it is called JID (JabberID). Every time user creates their user id in XMPP based application, this JID works as their virtual identity on the network. This JID looks much like an email address, it contains all the information required to contact users. Both client and server have JIDs. These JIDs are not limited to old ASCII character range.
Real time communication system using XMPP composed of three broad categories of communication. In XMPP this communication is known as stanza. There are three basic kinds of stanzas message, presence and info/query. XMPP stanzas have the following attributes in common:
From: The JID of the source XMPP entity.
To: The JID of the intended XMPP recipient.
Id: An optional identifier for the conversation.
Type: Optional subtype of the stanza.
XML:Lang: Language in which the textual description is written.
4.4.1 Message Stanza:
This is the basic method for getting information from one place to another after the communication is established. There are five types of message stanzas normal, chat, group chat, headline and error. Each of these stanzas is differ in their types.  In this project all of above except normal stanza are used. Message stanzas are also used to provide real time web interface.
Chat: These stanzas are exchanged in a real time while instant messaging.
Group chat: These stanzas are exchanged in multi-user chat room.
Headline: These stanzas are used to send alerts and notifications. Senders can not expect a response at all.
Error: If any error occurs during the communication, the entity that detects the problem will return a message of type error.
Message stanza contains only 3 elements body, subject and thread. Example of a simple message stanza,
<message from="firstname.lastname@example.org" to="email@example.com"type="chat">
<body>How are you?</body>
4.4.2 Presence Stanza:
Presence is the important feature in real time communication. Presence advertises the network availability of other entities and thus enables users to know whether other entries are online and available for communication. In order to see your presence, other person needs to send you a subscription request which you need to approve. Once you have approved the subscription, that user will automatically receive regular notification about your network availability. In this project XMPP presence state has been extended to some common state like online, busy, away, pending, invisible and offline. In this project presence is typically displayed in the roster. Roster is a presence enabled contact list which usually contains list of JIDs. Presence stanza made up of 3 elements show, status and priority. Priority element of the presence stanza is an optional element which is used to sets the priority of the added JIDs. The priorities can be set from -127 to 128. JID sets with negative priority will never receive this message.  Example of simple presence stanza,
4.4.3 Info/Query Stanza:
The Info/Query stanza provides a structure for request response mechanism. It is similar to the GET, POST and PUT method from HTTP. IQ stanzas provide a more reliable transport that is optimized for a structured exchange of data. IQ stanza contains only one payload, which defines the request to be proceed or action to be taken by the recipient. Request and responses are tracked using the id attribute which is generated by the requesting entity and then included by the responding entity.
Using IQ Stanza users can add new contact to their rosters. An IQ-set creates, delete or update any kind of information.  The type attribute has special values in IQ stanzas,
Get: The requesting entity asks for account information.
Set: The requesting entity provides some information or make request.
Result: The responding entity provides the result of a get operation.
Error: The requesting entity such as XMPP Server notifies the requesting entity that it was unable to process the get or set request.
Example of IQ Stanza,
id="rr82a1z7" to="firstname.lastname@example.org" type="get">
XML Stanza can also contain any number of other child elements including XHTML-formatted message bodies, pointers to URLs, RSS, forms to be filled out and a wide range of other payloads. XMPP is a pure XML technology hence it makes extensive use of XML namespace.
4.5 Error Handling
XMPP does not acknowledge every message that is sent over network. Instead in XMPP IQ stanzas are more structured, it always generates either an IQ-result or IQ-error in response to an IQ-get or IQ-set. Errors are reported by setting the stanza's type attribute to a value error, along with an <error/> child element. The type attribute of the <error/> element is one of cancel, continue, modify, or wait. In addition to the stanza error conditions, some conditions are also defined for stream errors and authentications errors. The main difference between these two errors are steam errors are unrecoverable and force to close the XML steam while stanza errors are recoverable and use to report the problem with particular stanzas. 
Simple example of how the stanza error looks like,
<message from="email@example.com" to="firstname.lastname@example.orgI"
4.6 Multiuser Chat
XMPP also supports group chat aka multi user chat including the processes for joining, participating in, and leaving a chat room. In multi user chat process client needs to reserve a nickname using the in-band registration protocol, imposing appropriate security and privacy measures. Owner or the creator of the chat room owns the authority to delete or ban users from the chat room. In XMPP, group chat is a particular room and it has its own JID. When user creates a chat room, name of the chat room is going to be the JID of that particular room. e.g. email@example.com. Owner of the chat room can add any of his friends from the contact list by adding his JID in to the chat room. When any other user wants to join this room, user sends his directed presence to the room including preferred nick name as the resource identity which is know as user's room JID. When any user join the chat room several things happen, 
The room sends a join notification from room JID to the other participants.
The room sends presence to the user from the JIDs of all other participants.
The room will typically also send some the recent messages exchanged.
4.7 File Transfer
4.7 File Transfer
In file transfer, the sender and receiver needs to establish a connection which allows them to transfer binary data stream. From its innovation XMPP is not optimized for data transfer. There are two methods defined in XMPP for managing binary data stream in-band and out-of-bound. In-band method is similar to the instant messaging where data is sent in piece of XML. In out-of-band method clients themselves needs to make separate connections bys sharing IP-address with each other. Out-of-band file transfer is much faster than in-band but it is less secure than in-band. This application uses different approach where user uploads a file to the server and server sends notification using XMPP message stantza to the desired receipent, and using this notification receipent user can download the appropriate file. This approach gives an advantage of transferring a file when the users are not available on the network. Using same method user can also send a file to the group of users during muli user conference.
4.8 Client-Server Connection
In XMPP a client session starts by connecting to a server and negotiating the session details, after which client can send message, presence and IQ stanzas to other entities on the network. The session ends when the client decides to close the steam. In XMPP setting up a client-to-server session consist of following phases,
Initiate a TCP connection to the server.
Opening an XML steam.
Negotiating Various Stram Features.
Authenticating with the server.
For IM application, requesting and sending initial presence.
So after the session has been started, the actual XMPP communication can start happening.
4.9 Server-to-Server Connection
When client needs to send a message to a contact on another server, server needs to connect to the other server before it can send the message through. Server-to-server connection basically follows the same pattern as client-to-server connection. After opening a connection to the host serving XMPP for the target JID, the sending server needs to authenticate itself before it is allowed to send a message.
The client to server and server to server connections are normally happen over long-lived TCP connection. Sometime it can be difficult to maintain long-lived TCP connection. The solution is to use a method that does not require the client to maintain a long-lived TCP connection. To overcome this issue Bidirectional-streams over Synchronous HTTP (BOSH) are used in which HTTP request/response pairs are synchronously used multiple times. BOSH based systems are normally deployed with a special connection manager that acts a proxy between the client and the XMPP server. In this project apache is used as proxy which works as connection manager between the client and Openfire XMPP server. 
In addition to the all above mentioned features XMPP provides service discovery features which is helpful to determine what clients and servers are available on the network and what are the XMPP features those entities implement. These can be done using disco#items and disco#info. 
CONCLUSION AND FUTURE WORK
Instant messaging has been always integral part of our lives and is extensively used. Embedding instant messaging with real time web based application it becomes more valuable. Biggest advantage of web based applications is they are available to broadest audience. Web based application allows user to use the application from any where at anytime irrespective of device or operating system.
In conclusion, this project demonstrates how ruby on rails can be used to develop user friendly web based applications. Ruby on Rails provide solid infrastructure to build a web application. This project also delivered its primary goal to implement XMPP architecture over ruby on rails. This project also explores compability of Ruby on Rails with other technology like AJAX, Java Script and MySQL. Through this project I have learned that good architecture and design produce high quality software application and has very fewer bugs.
For future work and enhancements, we can extend the application to support on large scale use and also implement wide verities of features. There is scope for significant future work on the project especially related to video conferencing. This application already supports flies sharing within a group, mutli-user chat rooms, using same scenario multi user video conferencing will be developed, where users can share their video with multiple users.
APENDIX A - INSTALLATION PROCEDURE
This section describes the procedure to install require software and procedure to execute web based chat application.
The following hardware and software is required to install and execute the web based chat application.
Computer with a 1GB RAM, 20 GB of available hard-disk space, Microsoft Windows XP with Service Pack 2 or higher versions, 1024x768 or higher-resolution display with 256 colors.
Java 2 SDK 1.4.2_13, MySQL 5.1, OpenFire 3.6.4, Instant Rails 2.0, Internet Explorer 7 or 8, Firefox 3 and higher, Safari 4, Chrome 4.
Chat (XMPP) Server Installation:
First of all install MySQL 5.1 and run MySQL Workbench to make connection with Openfire Server. Create a new MySQL database for Openfire server users. By using MySQL, application can add, edit, delete, and query all XMPP server users, as well as scale your XMPP infrastructure in line with your web infrastructure. Once the database has been created you need to install Openfire 3.6.4. Select MySQL as a database driver during Openfire Configuration. This will work as your Chat Server which will maintain all the real time data.
Web server Installation:
Once you have installed Instantrails, apache needs to be configured to forward XMPP over BOSH. Openfire maintains an HTTP binding URL for access over BOSH at http://localhost:7070/http-bind. To use this on port 80 configure apache HTTP server to forward a URL to this location. For this proxy module in http.conf, apache configuration
file needs to be enabled and the loadmodule entries for mod_proxy.soÂ andÂ mod_proxy_http.so also need to be added to enable proxy support. Also copy following code in httpd.conf file.
ProxyPass /xmpp-httpbind http://127.0.0.1:7070/http-bind/
ProxyPassReverse /xmpp-httpbind http://127.0.0.1:7070/http-bind/
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000
After successfully installing web server and chat server, before deploying the chatapplication using ruby on rails Mongrel server, copy following line in instant rail's windows host file.
Now when you execute www.chatapplication.com in your browser you will be able to see web-based chat application login page.