Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Assignment 4, you wrote a simple web browser client. This time around, you will write a multithreaded webserver which will serve HTML files from

image text in transcribedimage text in transcribed

In Assignment 4, you wrote a simple web browser client. This time around, you will write a multithreaded webserver which will serve HTML files from the filesystem to a browser client. Write a program called Webserver.java that creates a ServerSocket object and then enters an infinite loop The program should take the Socket returned by the ServerSocket's accept O method, create a Runnable object that uses the Socket, pass this object to a Thread, start the Thread running, and go back to waiting for another client connection The Runnable object will handle establishing the connection and serving the file. You already know what the client's handshake string looks like: GET HTTP/1.1 Your server should receive this string and extract the name of the file. If the request is empty (i.e., the name of the file is simply/), then by convention the server should load a file called "index.html" You will need to look for the requested file on the filesystem and load it into memory. You will then respond to the client's request using the simplest possible HTTP response: HTTP/1.1 200 OK r Content-type: text/html Backslash-r and backslash-n here correspond to the carriage return and new line characters respectively. After you send these lines, you should send the text file. If the browser asks for a file that does not exist, you should instead send the response HTTP/1. 1 404 Not Found r n If anything else goes wrong you can try to send HTTP/1.1 500 Internal Server Error This server is extremely insecure, and will allow a malicious user to access any textfile on your machine. You should implement a check so that the server will only send files that are located inside a particular directory designated by you. If the user tries to navigate outside of that directory (by using the parent-directory symbol) the server should not permit it. In Assignment 4, you wrote a simple web browser client. This time around, you will write a multithreaded webserver which will serve HTML files from the filesystem to a browser client. Write a program called Webserver.java that creates a ServerSocket object and then enters an infinite loop The program should take the Socket returned by the ServerSocket's accept O method, create a Runnable object that uses the Socket, pass this object to a Thread, start the Thread running, and go back to waiting for another client connection The Runnable object will handle establishing the connection and serving the file. You already know what the client's handshake string looks like: GET HTTP/1.1 Your server should receive this string and extract the name of the file. If the request is empty (i.e., the name of the file is simply/), then by convention the server should load a file called "index.html" You will need to look for the requested file on the filesystem and load it into memory. You will then respond to the client's request using the simplest possible HTTP response: HTTP/1.1 200 OK r Content-type: text/html Backslash-r and backslash-n here correspond to the carriage return and new line characters respectively. After you send these lines, you should send the text file. If the browser asks for a file that does not exist, you should instead send the response HTTP/1. 1 404 Not Found r n If anything else goes wrong you can try to send HTTP/1.1 500 Internal Server Error This server is extremely insecure, and will allow a malicious user to access any textfile on your machine. You should implement a check so that the server will only send files that are located inside a particular directory designated by you. If the user tries to navigate outside of that directory (by using the parent-directory symbol) the server should not permit it

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: 3

blur-text-image

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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Discuss the five types of learner outcomes.

Answered: 1 week ago