Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1 Implement a simple web server that accepts multiple client connections on some predefined port (e.g., 8888) using the ServerSocket class. The server should

Problem 1

Implement a simple web server that accepts multiple client connections on some predefined port (e.g., 8888) using the ServerSocket class. The server should serve (at least) HTML and PNG files from a local directory, using the GET method in the HTTP protocol. The response from the server should include correct and relevant headers as well as the requested file. The server should run until you terminate it.

The port and the root directory with the files should be passed as command line parameters (in that order).

Start by implementing a server that accepts connections and returns a predefined (valid) HTTP/HTML response. Once you can connect to the server with a web browser and view the predefined HTML page, you should add support for reading HTML files from disk and returning these. Finally, add support for images (binary files).

If a user requests a specific directory, e.g. / or user1/pages and this directory contains an index.htm or index.html file, then this file should be returned. Note that the ending / is optional, so http://myserver.com/user1 and http://myserver.com/user1/ should both return the index.html file in the user1 directory.

Prepare a few HTML and PNG files in a directory hierarchy and use this to test your web server. Make sure to include both index.html files as well as other named HTML files, e.g., myfile.html. Your report should include screenshots of the browser window when you request a named HTML page, an image, and a directory (with an index.html file).

Your web server should handle possible exceptions. You can assume that the user will only request files and directories that exist.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is server virtualization?

Answered: 1 week ago