Simple AJAX (with JSON) Chat Application for ASP 3.0
The code in this package (not only a snapshot, but also a darcs repository) was originally developed for two reasons: for use in teaching a course in Javascript as part of a guest lecture series for the University of Westminster, and as a consequence of my personal interest in experimenting with modern client-server programming techniques.
It’s a very, very simple chat application using XmlHttpRequest to communicate in an AJAX style with an ASP 3.0 server that processes JSON-RPC-like requests and manages a simple shared database.
The reason ASP 3.0 was chosen is because it was the server-side environment in place at the University laboratories for the course I was teaching. Programming in JavaScript on both the client- and server-sides simultaneously was a pleasant experience; modern environments such as Helma have a lot going for them.
If you take a look at the code, you’ll see that I use the term “AJAJ” often: the idea is to take the core elements of AJAX, but replace the unwieldy XML with something lighter-weight and better fitted to Javascript programming. In this case, the “X” for XML is replaced by “J” for JSON, which is a lightweight data language that is particularly convenient for working with Javascript.
Code overview
The application depends on a few third-party libraries that make programming in Javascript a little more pleasant. These are the parts of the application that I wrote:
simple-chat-client.html: Contains the HTML user-interface to the service, and the basic client-side Javascript code for driving the specifics of the chat service.
chat-server/simple-chat.asp: Contains the server-side code responsible for responding to the client’s RPC requests for chat-server functionality. Does not itself present any HTML at all: it only speaks AJAJ, accepting JSON requests and replying with JSON responses.
js/ajaj.js: Implements the client side of the AJAJ RPC library, building upon json.js.
chat-server/ajaj.asp: Implements the server side of the AJAJ RPC library, building also upon json.js (in the form of json.asp). The only part of this file not authored by LShift is the contained VBScript function BinaryToString, which was written by Antonin Foller and comes from http://www.pstruh.cz.
js/console.js: A reusable Javascript DHTML evaluator. Useful for debugging and interactive development of Javascript-bearing HTML pages.
js/util.js: A collection of utilities lending, among other things, a functional-programming flavour to Javascript.
chat-server/jsondb.asp: A simple (toy) transactional database driver for ASP 3.0 using the filesystem as a data store.
The following files are mostly library code from third parties:
js/json.js, chat-server/json.asp: Almost identical files - the only difference between them is that the .asp file contains the necessary boilerplate punctuation required to fit it into an ASP 3.0 environment. Both implement JSON serialization/deserialization. The only change made to the standard json.js distribution is LShift’s addition of the “@constructor …” syntax.
js/prototype-1.4.0_pre4.js, js/scriptaculous-js-1.5_pre4: a collection of convenient Javascript utilities for network and user-interface programming, from http://prototype.conio.net/ and http://script.aculo.us/ respectively.
5 comments October 11th, 2005 tonyg