Supplemental COMP361 Lab -   A Simple Web Server using TCP

revised 02/19/2004 10:36 AM +0800

This code is provided for your benefit.  Nothing needs to be submitted.

This is  a supplemental lab that permits you to run a stripped down web server on one machine and access it using a web browser on another machine.

This code has been tested and runs if both the web server and browser are running on the  lab2 machines csl2su1.cs.ust.hk  --  csl2su41.cs.ust.hk.  Please note that, due to firewall restrictions put in place for security reasons by cssystem, you can not access a webserver  running on a lab2 machine using a web browser running outside the CS UG  domain. So,  for example,  if you run the web server on csl2su1,  you will not be able to access it using a web browser running on a  machine in your hall.

What to do:

  1. Download the following programs and insert them all into the same directory on a lab 2 machine
    1. WebServer.java         
      • The webserver code from section 2.8 of the code. This webserver will terminate after servicing  a request.  Uses port 6789
    2. WebServerPro.java    
      • A slightly improved model. This webserver will run (servicing requests) until killed from outside. Also uses port 6789
    3. index.html
      • A simple web page to be retrieved by the web server
    4. BANNER.GIF
      • A GIF file linked to by index.html
    5. BANNER.jpg 
      1. A JPG file linked to by index.html
  2. Compile the code by running  javac WebServer.java   and   javac WebServerPro.java
  3. Log onto two machines
  4. On machine one (the server) run  java Webserver to run the web server. Be sure that you are running it in the same directory that contains  index.html,  BANNER.gif and BANNER.jpg.
  5. On machine two start up Internet Explorer (type "iexplorer")  and type in the URL http://machinename.cs.ust.hk:6789/index.html   and see what happens. 
  6. Try clicking on the line "click here to get a jpg file".  Note what happens?  Why does this happen?
  7. Now, on machine one run  java Webserver to run the web server again.
  8. On the browser on machine two request http://machinename.cs.ust.hk:6789/BANNER.jpg.  What happens?
  9. Now,  on machine one run java WebserverPro to run the "improved" web server.
  10. Again type in http://machinename.cs.ust.hk:6789/index.html.  After the web page comes up, click on "click here to get a jpg file".  What happens.  Why is this different than before?