This is a simple multi-threaded web server built using Java.
The project directory contains the following files:
-
ClientHandler.java
- This file contains the
ClientHandler
class which implements theRunnable
interface. It handles client requests by reading the request line, parsing headers, and generating appropriate responses. It also logs the requests using theLogger
class.
- This file contains the
-
Logger.java
- This file contains the
Logger
class which provides a static methodlogRequest
to log client requests to a file namedserver_log.txt
. It logs the client's IP address, the requested file name, and the response type along with a timestamp.
- This file contains the
-
www/index.html
- This file is the default HTML file served by the web server. It contains a simple HTML structure with a title and a heading for the COMP5311 Project.
-
WebServer.java
- This file contains the
WebServer
class which initializes the server, binds it to a specified port, and listens for incoming client connections. It creates a newClientHandler
thread for each connection to handle the client's request.
- This file contains the
To compile and run the web server, follow these steps:
-
Open a terminal and navigate to the project directory.
-
Compile all the Java files using the following command:
javac *.java
-
Start the web server by running the
WebServer
class using the following command:java WebServer
-
Open a web browser and navigate to
http://127.0.0.1:8080
to access the default HTML file (www/index.html
) served by the web server.