Question: please do it in java 2 Your own webserver (35 points) In Assignment 4, you wrote a simple web browser client. This time around, you

 please do it in java 2 Your own webserver (35 points)

please do it in java

2 Your own webserver (35 points) In Assignment 4, you wrote a simple web browser client. This time around, you multithreaded webserver which will serve HTML files from the filesystem to a browser client. Write will write a 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 acceptO 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 OK Content-type: text/htmllrnlrln 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 Found If anything else goes wrong you can try to send HTTP/1.1 500 Internal Server Errorrn Important: 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 Note: By convention, webservers should run on port 80. However, many operating systems protect 2- and 3-digit port numbers for security reasons, and running a Java webserver on port 80 would require running the program with admin to choose port 8000 or 8080 for running webservers in development (like yours are). If you are running your server on port 8080, you can access it with any standard browser (Safari, Firefox Chrome, etc.) by pointing it to "http://localhost:8080" istrative permissions. For that reason, it is common Extra credit: Allow the server to serve images as well as HTML files. Check the filename and if it ends with "pg", change the HTTP content-type from text/html to "image/jpeg, and load and transmit as a binary file rather than a textfile. 2 Your own webserver (35 points) In Assignment 4, you wrote a simple web browser client. This time around, you multithreaded webserver which will serve HTML files from the filesystem to a browser client. Write will write a 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 acceptO 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 OK Content-type: text/htmllrnlrln 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 Found If anything else goes wrong you can try to send HTTP/1.1 500 Internal Server Errorrn Important: 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 Note: By convention, webservers should run on port 80. However, many operating systems protect 2- and 3-digit port numbers for security reasons, and running a Java webserver on port 80 would require running the program with admin to choose port 8000 or 8080 for running webservers in development (like yours are). If you are running your server on port 8080, you can access it with any standard browser (Safari, Firefox Chrome, etc.) by pointing it to "http://localhost:8080" istrative permissions. For that reason, it is common Extra credit: Allow the server to serve images as well as HTML files. Check the filename and if it ends with "pg", change the HTTP 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!