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:
- Download the following programs and insert them all into
the same directory on a lab 2 machine
- WebServer.java
- The webserver code from section 2.8 of the code. This
webserver will terminate after servicing a request. Uses port
6789
- WebServerPro.java
- A slightly improved model. This webserver will run
(servicing requests) until killed from outside. Also uses port 6789
- index.html
- A simple web page to be retrieved by the web server
- BANNER.GIF
- A GIF file linked to by index.html
- BANNER.jpg
- A JPG file linked to by index.html
- Compile the code by running
javac WebServer.java and
javac WebServerPro.java
- Log onto two machines
- 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.
- 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.
- Note machinename is the machine upon which you are
running the web server, e.g.,
http://csl2su1.cs.ust.hk:6789/index.html
- the 6789 is the port at which you are requesting service.
The default port used by web browsers is 80 so you need to explicitly direct
it to port 6789
- Note that after servicing the request the web
browser shut down.
- Try clicking on the line "click here to get a jpg file".
Note what happens? Why does this happen?
- Now, on machine one run
java Webserver
to run the web server again.
- On the browser on machine two request
http://machinename.cs.ust.hk:6789/BANNER.jpg. What happens?
- Now, on machine one run
java WebserverPro
to run the "improved" web server.
- 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?