Develop a simple web server in two steps in the end you


Part -1:

Develop a simple Web server in two steps. In the end, you will have built a Web server that is capable of processing simple web requests such as an HTML page with embedded images. You should be able to demonstrate that your Web server is capable of delivering a simple home page to a Web browser.

As you are developing the code, you can test your server from a Web browser. But remember that you are 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, if you are testing your program on toolman, your server is listening to port 5910, and you want to retrieve the file index.html, then you would specify the following URL within the browser

To simplify this programming task, you should develop the code in two stages. In the first stage, you will write part of the server that simply displays the contents of the HTTP request message that it receives. After this program is running properly, you will add the code required to generate an appropriate response.

Write a java program named HttpServer.java that opens a TCP socket at a user specified port to listen to HTTP GET requests. This should be relatively easy and similar to the TCP Socket programs that we wrote in class. Create a S that listens for incoming client requests at a specified port. When the server receives a request, obtain the input and output streams from the socket. Read the HTTP packet from the client as a set of strings, each of which is terminated by a line feed (\n). Once the packet is read, display the content to the screen.

How would you know that you are done reading the packet?

The last string should have length zero since it only has a carriage return (\r) and line feed (\n) character in it.

Part -2:

In this assignment, you will complete the web server that you started in the last assignment. At this point, your program should be able to analyze the HTTP packets sent by the browser. You will need to implement the HTTP GET method alone for completing the assignment. At the end of this assignment, your web server should be able to deliver a simple HTML web page with an embedded image.

Your program should parse the HTTP packet sent by the client to obtain the filename requested by the client. Look at the StringTokenizer java class to see how you can use it to parse the request line in the HTTP packet. You can ignore the header lines, since we are not interested in these in the assignment. In case if the file is not found, you should generate a response with status 404 Not found response. How can we generate this response? The HTTP response has three main parts - thes status line, header lines, and the Entity body. You would need to populate these values, and send these as a stream of bytes to the client. An example code snippet is given for your benefit.

Solution Preview :

Prepared by a verified Expert
Computer Networking: Develop a simple web server in two steps in the end you
Reference No:- TGS0936283

Now Priced at $50 (50% Discount)

Recommended (91%)

Rated (4.3/5)