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/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.

Interesting… I’m playing with it now. I like the fact that it uses JSON and XMLHTTPRequest.

I’m currently investigating the best ways to create a chat app like you’ve done here using JSON and AJAX… however, I’m planning on a bit more functionality. Some things that I’m planning on using may include AFLAX (www.aflax.org) and Taconite libraries (find it at Sourceforge). For fluff, I’m going to use moo.fx with scriptaculous as well.

A few things that I think are interesting but not workable for me are the use of a single file as the database… however, when someone new logs in, they shouldn’t be able to see all the prior conversations… however, the old ones “could” easily be jammed into an array quickly, sorted, and removed (filtered) from the array prior to sending off the the client. By doing so, it could be possible to even make “private” conversations only shown to the recipients…. now that would be very clever.

BTW, what method are you using for pulling the data?… is it merely a timer checking every few seconds?

Hi Tony!
I was searching on the web if there was someone else working on JSON-RPC and ASP3.0 and it was a nice sourprice to find your site.

I’ve been developing a proxy to make function calls from the browser to the web server (also Asp3 with javascript). The main difference between yours and mine, is that I implemented an object that lets you export almost every function, or object from the server to the client.

It allows me to call the functions syncronously (like the first example) or asyncronously (like the second one) , stop the calls, or allow one call per function, cache the results ( in a Response.expires similar way) , transform recordset results to JSON results, etc.

I’m developing it as long as I need functionalities, so I didn’t make any manual or demos. I’m using it on my current projects. ..But If you are interested I could manage some way to show you some examples.