Sat, Oct 18, 2008 – Stanford Splash

Splash: Advanced Computer Networking

In this class we learned about writing internet servers. First we looked at web servers and three different ways of writing them; second, we looked briefly at an IM server.

Below you'll find the code we discussed in class and some resources to help guide you forward.


These examples are written in Python; you can run them from a command line using:

$ python 8080

(Replace "" with the appropriate file name for each example, and of course, choose whatever port number you like.)

To connect to these servers, you can either use a web browser (for the web servers, anyway) and point it to http://localhost:8080/, or use telnet in a separate terminal window.

$ telnet localhost 8080

When you get to a prompt, use HTTP for the web servers, and use the IM protocol (desribed below) for the IM server.

  1. The simplest web server ever.
    No matter what request comes in, it always prints the same thing.

  2. A threaded web server.
    Each new request is handled by its own thread, created by os.fork().

  3. An "async" web server.
    Back to a single thread, but with non-blocking input and output (I/O).

  4. An "async" IM server.
    An example of writing your own protocol. Also has non-blocking I/O.

The IM Protocol

There are a number of commands you can use:


There are many resources on the web to help you write a server. A good place to start is to look at the Wikipedia pages for:

If you're interested in writing servers in the Python language, be sure to check out the Python documentation. The library we used for non-blocking I/O, asyncore, has some good references on the site:

Contact Me

If you have any other questions, drop me a line at