A web server is just a machine connected to the Internet, running a computer program that listens to requests for content, such as HTML files. Those requests come from programs, such as browsers, running on other computers also connected to the Internet. For this to work, there has to be an agreed language for both the requests and what's sent back. That language is the HyperText Transfer Protocol (HTTP).
Rather than repeat what's been written many times, I refer you to
The nice thing about the web is that all communication between programs is done using HTTP, which uses simple commands in plain text. That simplicity means that you can write a web server or browser in any language you like, as long as it lets you read and write to the network.
Writing a server or browser from scratch would be pretty tedious, though. Fortunately, many languages now have code libraries to take care of such details as reading and writing characters to the network, parsing HTTP commands, creating threads (lightweight parallel processes) for each request to support simultaneous users, and so on.
For Common Lisp there are two major code libraries for web services:
In this course, we use Franz, Inc.'s AServe library, for a number of reasons:
For those students not using Allegro, there is a portable AServe library that runs in a number of Common Lisp's. I use it in LispWorks Personal Edition.
.Switch to the cs325-user package in your Listener window:
(in-package :cs325-user)
You make URL's available to users with functions like
publish, publish-file,
and publish-directory.
These functions link specific URL's to Lisp functions or HTML files.
(This corresponds to servlet mappings
in Java web applications.)
To test AServe on your system,
(require :aserve)portableaserve/INSTALL.lisptest-aserve.lisp
(net.aserve:start :port 8000)8000 is a port. Ports are simply numbers operating systems use
as a kind of address to determine which program should process a
network message. Low numbers are pre-assigned to standard services, e.g.,
80 is the default for a web server. For development, use a safe high number.
In the unlikely case that your machine is already using port 8000
for some service, try some other number over 1024. Use that number in
your localhost URL.
If you have a firewall running on your machine, and you should, the first time you start the server, you should get an alert saying that your Lisp is trying to access the network. Tell your firewall this is OK.
The URL http://localhost:8000/
should take you to a page published by the code in
test-aserve.lisp.
If it doesn't, look at the error message you got.
test-aserve.lisp.
again and make sure there are no errors.The home page published by
test-aserve.lisp.
has links to several examples of things you can
do with the AServe package:
These are all very simple examples. Use the code in
test-aserve.lisp
to guide you
when creating other Lisp-based web pages.
While your server is running, any machine on the Internet can
access your pages. To access your server from another machine,
replace localhost with your server's Internet name or IP address.
For example, if your machine's IP address was
555.100.10.100, then you could critique Lisp by
typing this URL in your browser:
http://555.100.10.100:8000/cs325/critic
To avoid hackers attacking your system, and to reduce system load, shut down AServe when testing is done:
(net.aserve:shutdown)
For more examples, see:
Comments?
Send mail to Chris
Riesbeck.