This project is a simple multi-threaded web server implemented in Java for Internet and Computing II.
It listens for incoming HTTP requests on port 6789 and serves static files (HTML, images, etc.) stored in the src/main/resources directory.
- Handles multiple client requests simultaneously using threads.
- Supports GET requests for static files (HTML, JPEG, GIF, etc.).
- Returns
404 Not Foundif a requested file is missing. - Serves files based on MIME type detection.
- The server starts and listens for incoming connections on port 6789.
- When a client requests a file (e.g.,
localhost:6789/index.html), the server:- Checks if the file exists.
- Reads and sends the file's content to the client.
- Sends an appropriate HTTP response header.
- If the requested file is missing, the server returns a
404 Not Founderror. - The server runs in a loop, handling multiple client requests using separate threads.
- Java Development Kit (JDK) 8 or later
- IntelliJ IDEA Ultimate (Recommended for running the project)
|-- src
| |-- main
| |-- java
| |-- SolicitudHttp.java
| |-- ServidorWebSimple.java
| |-- resources
| |-- index.html
| |-- 404.html
| |-- cat.jpg
| |-- cat.gif
- Open the project in IntelliJ IDEA Ultimate.
- Ensure that you have the correct SDK set up.
- Navigate to
ServidorWebSimple.java. - Click on the Run button or use the shortcut
Shift + F10to start the server. - The server will start listening on port
6789.
Once the server is running, open a web browser and enter the following URLs:
http://localhost:6789/index.html- Displays the index page.http://localhost:6789/cat.jpg- Displays thecat.jpgimage.http://localhost:6789/cat.gif- Displays thecat.gifimage.http://localhost:6789/nonexistent.html- Displays a404 Not Foundpage.
- The server serves files located in
src/main/resources. - Ensure the requested file exists in the directory to avoid
404errors. - The server currently only supports
GETrequests.