HTTP servers implemented using Clean

Martin Wierich martinw@cs.kun.nl
Thu, 07 Sep 2000 09:34:54 +0200


Hi all,

Paul wrote:
>Actually I do not have experience in using Clean as a http server (maybe
>Martin Wierich who created the tcp/ip library can tell you moer about this),

Yes I can.

The problem "server" is intrinsically parallel. Ideally one would like to create a different thread for every connection
to a client and let these threads handle the communication independently. If one thread would block (e.g. because he is
waiting for data to arrive) the others could still proceed.

The Clean compiler produces only sequential code so you have no means for concurrency (threads). This makes things more
difficult. There are two approaches to handle blocking:
- multiplexing: the TCP library exports a function "selectChannel" (similar to the sockets API function "select").
  This function takes as input a collection of channels and returns a number that identifies the channel on which at
  first some data (or a connection request) arrives.
- event driven programming: When data arrives a callback function is executed to handle this event. 

The multiplexing approach is far more easy to implement. Event driven programming is not that nice (lots of state
transitions). Use events only in combination with GUI programming.

The TCP library distribution contains a "chat" server and an "echo" server application (and the corresponding clients).
The chat server is based on multiplexing, the echo server is event driven.

Two students at our university implemented an event driven HTTP server. Maybe someone here remembers their names so that
we can ask them to post their experiences.

cheers
  Martin Wierich
  University of Nijmegen