How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Scott Your Own Question
Scott
Scott, MIT Graduate
Category: Homework
Satisfied Customers: 3040
Experience:  MIT Graduate (Math, Programming, Science, and Music)
3546829
Type Your Homework Question Here...
Scott is online now
A new question is answered every 9 seconds

Need help with a multi-threaded Web server assignment that

Customer Question

Need help with a multi-threaded Web server assignment that should be capable of processing multiple service requests simultaneously.

http://wikisend.com/download/385748/ProgramDescript.docx

Submitted: 6 months ago.
Category: Homework
Expert:  Bruce Wilner replied 6 months ago.

Tell me more about what you are expected to deliver; what development language; what classes are already implemented.

Customer: replied 6 months ago.
It's suppose to be in java(I'm using net beans) and I just started working on the program myself since it looks kind of difficult. But everything is in the file I shared.
Expert:  Bruce Wilner replied 6 months ago.

Beans doesn't have beans to do with the requirement :-)

I wonder why--if multithreaded is such a wonderful approach--there's no standard library for making things multithreaded.

Here's a secret for you: multithreading is a sham. A competent operating system scheduler would completely obviate the need to use threads for a process which is already primarily I/O-bound.

However, the point is to separate the task of accepting inbound requests from the task of launching subprocesses to address the requests. Ironically, on UNIX at any rate, this wouldn't be the responsibility of the Web server, but of the Internet superserver, inetd, which would launch an independent httpd instance for each incoming request. As for Windows, only paraprofessionals use Windows. UNIX was built of, by, and for computer scientists. Windows was built as if by children. Just take a look at some of the problems/requests that come into JustAnswer (if you have access to): with UNIX (Macintosh at any rate), people may have usage issues, but the typical Windows issues are of the kind, "It doesn't work."

Customer: replied 6 months ago.
Relist:All the requirements are in the file. If you have question let me know.
Expert:  Bruce Wilner replied 6 months ago.

Please post them DIRECTLY in the Messages stream. You will find MANY experts here reluctant to code to "requirements" that mysteriously live in outside files not under the control of JustAnswer. They are capable of changing all by themselves--unlike requirements that are CLEARLY memorialized directly on this Request page.

You and your professor should learn--as quickly as possible--that the only "service" that these drop boxes provide is an efficacious means for large companies to STEAL others' intellectual property. I personally will have nothing to do with them. Oh, that, and they can expediently mine and send the stuff to Uncle Sam.

Customer: replied 6 months ago.

Program Description:

You will develop a multi-threaded Web server that is capable of processing multiple service requests simultaneously. You should demonstrate that your Web server is capable of delivering a web page to a Web browser

(the Client). The web page may include other objects such as pictures. The Server runs a simplified

HyperText Transfer Protocol (HTTP)that responds to the GET request message only. Port number 5764 will be used for connection requests. Each request should be handled with a separate thread.

You can test your Server with a Web browser. But remember the Server is NOT serving through the standard port 80, so you need to specify the port number within the URL that you give to your browser. For example, let’s assume the host name is host.someschool.edu, the Server is listening on port 5764, and the web page to be retrieved is index.html.Then you must type the following URL in the browser: http://host.someschool.edu:5764/index.html. If you are running the Server and the browser on the same machine, you would type: http://localhost:5764/index.html. If you omit ":5764", the browser will assume port 80 which most likely will not have a server listening on it. When the server encounters an error, it sends a response message with the appropriate HTML source so that the error information is displayed in the browser.

Customer: replied 6 months ago.
Program Requirements

  1. System output must show your Server is currently running. You must try-catch everything and print out appropriate error messages identifying the specific exception. The Server must not crash under any situations.

  2. You MUST have 3 classes implement the WebServer, HTTPRequest (the Server Thread class) and the HyperText Transfer Protocol. Follow the instructions below.

Customer: replied 6 months ago.

WebServer class :

The Web Server will be multi-threaded, where the processing of each incoming request will take place inside a separate thread of execution (HTTPRequest). You must have a run() method in WebServer class. When a connection request is received, create an instance of HTTPRequest thread with the Socket object that is created to handle the connection.

Customer: replied 6 months ago.

HTTPRequest class(Sever Thread class):

This class extends Thread class and you must implement the run() method that handles the Client socket I/O. You must use an instance of HTTP class to handle the request and response messages from/to the Client.

Customer: replied 6 months ago.
HTTP class

This class implements a simplified version of the HyperText Transfer Protocol that handles the GET request message and composes the response message to be sentto the browser. For the request message from the Client (browser), you only need to parse the first line, and the method is always GET. The format of the first line of the HTTP request message is as follows.

Method

SPACE

URL

SPACE

HTTP

Version

\r

\n

  • Parsing the request message

You will read the request message from the socket's input stream and parse the request message. The readLine() method of the BufferedReader class will extract characters from the input stream until it reaches an end-ofline character, or in this case, the end-of-line character sequence (\r\n).

Extract the file name (URL) only from the request line with the StringTokenizer class. Because the browser precedes the filename with a slash, prefix a dot to the file nameso that the resulting pathname starts within the current folder. For example, fileName = "." + fileName;. Next,create an instance of the FileInputStream as the first step of sending the file (might be a web page or other objects such as a gif file) to the Client. If the file does not exist, the constructor will throw the FileNotFoundException. Instead of throwing this possible exception and terminating the thread, you will use a try/catch construction to set the boolean variable fileExists to false. Later in your code, you will use this flag to construct an error response message, rather than try to send a nonexistent file.

  • Composing the response message.

There are three parts to the response message: the status line, the response headers, and the entity body. According to the HTTP specification, you need to terminate each line of the Server's response message with a carriage return

(\r) and a line feed (\n), so you might want to define a constant CRLF as a convenience. Send the response message in sequence by writing to the socket's output stream. The status line and response headers are terminated by the character sequence (\r\n), and the entity body (the HTML file) is preceded by a blank line (\r\n). The format of the status line is as follows.

Version

SPACE

Status Code

SPACE

Phrase

\r

\n

Always use “HTTP/1.0” as the version.The status code and the phrase are “200 OK” if the file is found, or “404 Not Found” if the requested object does not exist. If you are using DataOutputStream, there is a writeBytes() method that writes a String to the output. The format for the header line is as follows.

Header Field Name

SPACE

Value

\r

\n

Always use “Content-type: ” as the header field name. The Value is the MIME type of the object requested. For example: text/html, image/gif, image/bmp, or image/jpeg. You could write a contentType() method that determines the MIME type. This method will examine the extension of a file name and return a string that represents its MIME type. If the file extension is unknown, we return the type application/octet-stream.

private String contentType(String fileName)

{ if(fileName.endsWith(".htm") ||

fileName.endsWith(".html")) contentTypeLine = contentTypeLine + "text/html\r\n"; if(?) ... ; if(?)

... ; return "application/octet-stream";

} //end of contentType()

You must have a method that writes the requested file (entity body) onto the socket's output stream. This method may throw an IOException. You MUST write the file with a 1024-byte chunk, meaning you must use the read(byte[] b) method in the FileInputStream class to read a 1024-byte chunk, and use the write(byte[] b, int offset, int len) method in the OutputStream classto write the chunk to the socket’s output stream. NOTE: the last chunk of the file is normally less than 1024 bytes. The read() method returns an integer indicating the number of bytes read. To construct a 1024-byte buffer to hold bytes:

byte[] buffer = new byte[CHUNK_SIZE];

Have a while loop to keep reading/writing from/to the socket until the end of file. The read() method returns -1 indicating an end of file. If the file is not found, your entity body should be:

entityBody = "<HTML>" + "<HEAD><TITLE>Not Found</TITLE></HEAD>"

+ "<BODY>Not Found</BODY></HTML>";

Customer: replied 6 months ago.
Relist: Incomplete answer. Price is negotiable by when it can be completed
Customer: replied 6 months ago.

Could I get this question closed????

Related Homework Questions