Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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) 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 (ie 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 OKr Content-type: text/htmlrin in Backslash-r and backslash-n here correspond to the carriage return and newline characters respectively. After you send these lines, you should send the contents of 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 Foundir In In If anything else goes wrong you can try to send HTTP/1.1 500 Internal Server Error in kn Important: This server is extremely insecure, and will allow a malicious user ainv le on your machine. You should implement a check so that the server will only send files that textfil are located inside a particular directory designated by you. If the user tries t that directory (by using the parent-directory symbol .") the serye should not permit it Note: By convention, webservers should run on port so. However, many operating systems protect 2- and 3-digit port numbers for security reasons, and running a would require running the program with administrative permission to choose lava webserver on port S0 s. For that reason, it is common ning webservers in development (like yours are). If you are port 8000 or 8080 for run ing your server on port s080, you can access it with any standard browser (Safari, Firefox Chrome, etc.) by pointing it to "http://localhost:8080 Extra credit: Allow the server to serve images as well as HTML files. Check the tilename and if it ends with jpg, clange the IHTTP content-type from text/html" to "image/jpeg", and load and transmit as a binary file rather than a textfile

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

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. The group answers the questions.

Answered: 1 week ago