Click here to Skip to main content
11,806,590 members (42,941 online)
Click here to Skip to main content

Writing ASP Chat using JavaScript and XML (Part 3)

, 21 Jan 2004 56.2K 1.1K 20
Rate this:
Please Sign up or sign in to vote.
Step-by-step article about writing web-based chat. This article explains the chat with users list and registration.

Sample Image - RegistrableChat.gif


Here, I added persistence of user information and registration. Upgrading User-friendly chat to Registrable chat requires adding persistent user information. New users must be able to register. Existing users can login using a username and password.

Registrable chat

On the start page, we need to add a password field and link to a registration page. The loginUser function is appended with a password argument. In this function, we replaced repeat authorization checking with user authentication by name and password. If the name and password are correct, a new session is created. Another important function is registerUser(nick, password, firstName, lastName, email). Both functions use a single store, which can be an XML file or a relational database. In this article, we use XML.

For performance reasons, XML data must always be in memory, and disk I/O operations should be infrequent. The previously written SharedXML class, with few improvements, will fit these requirements. The only improvements required are two functions: save(fileName) and load(fileName), to write and read the whole XML on disk appropriately. For accessing single node attributes, use UserInfo class. To maintain good architecture design, we use the UserDataXML class, which encapsulates logic for working with SharedXML and UserInfo classes.

The data persistence algorithm is as follows.

Data loading

Initial data load must be on application startup or on first data access. For simplicity, we use the Application_OnStart event.

function Application_OnStart() {
    // Initial data load.
    var usersData = new UsersDataXML;

Data saving

Saving of data should be performed each time a change occurs; in our case this is only registerUser call. If data changes occur frequently, then we should use an auto-saving mechanism. Here, the save operation is invoked by the same functions, but with refractory period. This means time, while the saving operation does not lead to real data writing. To implement this possibility, we should use the UserData_autoSave() method. Also, in this scenario, we require a final call to save data before the application is terminated. In ASP, this is the Application_OnEnd() routine.

Note, XML DOM requires physical memory that is ten times larger than the file size itself.

Another important activity is providing valid file path and read-write access permissions. If a file does not exist, it will be created after the first user registers, by registerUser() method.

Registrable Chat requires folder with read-write permissions. It can be a DB folder, which is not a subfolder of the web application. For example: <Your local path>\Samples\RegistrableChat\DB\.


Are You still looking for something more? In the next part, you will see how to create a chat with multiple rooms.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Alexander Fedorenko
Web Developer
Ukraine Ukraine
Alexander Fedorenko is a professional C++ developer since 1996. He completed many custom and shareware projects. One of the successful projects is DevPlanner - tool for personal planning and time management.

You may also be interested in...

Comments and Discussions

GeneralUnable to Download source files Pin
kasa248930-Dec-13 21:59
memberkasa248930-Dec-13 21:59 
GeneralRe: Unable to Download source files Pin
Alexander Fedorenko31-Dec-13 3:01
memberAlexander Fedorenko31-Dec-13 3:01 
GeneralDelete users Pin
kinghenry2315-Mar-11 1:47
memberkinghenry2315-Mar-11 1:47 
Questioncustomer support Pin
Moukala29-Oct-06 23:29
memberMoukala29-Oct-06 23:29 
QuestionProblem with Registering Pin
kango28-Oct-05 3:31
memberkango28-Oct-05 3:31 
AnswerRe: Problem with Registering Pin
Alexander Fedorenko28-Oct-05 8:10
memberAlexander Fedorenko28-Oct-05 8:10 
QuestionWhere is the article? Pin
theJazzyBrain26-Jan-04 7:02
membertheJazzyBrain26-Jan-04 7:02 
Frown | :(
Some people here have misunderstood what writting an article means...

The point is not to show off what you have done, but:

1) Actually explain each feature
2) Discuss why you did some things the way you did them and why you didnt do them in some other way
3) What else has been done and what else could be done
4) The technologies that you used and that you didn't use and why...
5) The problems that you faced...

In addition, many people divide a single regular size article in many "PARTS" so they can have more articles posted on here, and each part is not even a scrollable page on a 800x600 resolution screen.


Why dont you browse around and have a look at some good and detailed articles. You will understand what I mean...

All I see is two small paragraphs of text and a file to downoad...

Its not only you... more people have done that in the past and the CodeProject people should do something about it...

Excelence is not an act, but a habbit

AnswerRe: Where is the article? Pin
Alexander Fedorenko27-Jan-04 0:26
memberAlexander Fedorenko27-Jan-04 0:26 
GeneralRe: Where is the article? Pin
theJazzyBrain28-Jan-04 0:22
membertheJazzyBrain28-Jan-04 0:22 
GeneralRe: Where is the article? Pin
Alexander Fedorenko28-Jan-04 0:44
memberAlexander Fedorenko28-Jan-04 0:44 
GeneralRe: Where is the article? Pin
theJazzyBrain28-Jan-04 23:29
membertheJazzyBrain28-Jan-04 23:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151002.1 | Last Updated 22 Jan 2004
Article Copyright 2004 by Alexander Fedorenko
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid