Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with this. Please provide full code of the server. import java.io.* ;

ID: 3905138 • Letter: N

Question

Need help with this. Please provide full code of the server.

import java.io.* ;

import java.net.* ;

import java.util.* ;

public final class WebServer

{

       public static void main(String argv[]) throws Exception

       {

       // Set the port number.

       int port = XXXXXXXXXX;

       // Establish the listen socket.

       …

      

       System.out.println("listening for connection");

      

       // Process HTTP service requests in an infinite loop.

       while(true) {

                  // Listen for a TCP connection request

                     …

                     // have a request now

                     System.out.println("received a connection request");

                     // Construct an object to process the HTTP request message.

                     HttpRequest request = new HttpRequest(connectionSocket);

                     // Create a new thread to process the request.

                     Thread thread = new Thread(request);

                     // Start the thread.

                     thread.start();

                  }

       }

}

final class HttpRequest implements Runnable

{

       final static String CRLF = " ";

       Socket socket;

       // Constructor

       public HttpRequest(Socket socket) throws Exception

       {

              this.socket = socket;

       }

       // Implement the run() method of the Runnable interface.

       public void run()

       {

          ….

       }

       private void processRequest() throws Exception

       {

       // Get a reference to the socket's input and output streams.

       …

       // Set up input stream filters.

       …

       // Get the request line of the HTTP request message.

       …

       // Display the request line.

       System.out.println();

       System.out.println(requestLine);

       // Get and display the header lines.

       String headerLine = null;

       while ((headerLine = br.readLine()).length() != 0){

       System.out.println(headerLine);

       }

      

       // Part A ends here

     

// this is where you will be adding code to implement part B

// extracting the filename from the request line, open the file

// if you are using eclipse don’t use the prepend of a “.”

// instead you need to find the FULL PATH NAME to where eclipse saved the

// index.html file you created as part of Part B. Most likely it is in

// C://users/…./eclipse- workspace/projectnameyouchose/WebContent/

// and then Construct correct response message     

      

       // Close streams and socket.

       os.close();

       br.close();

       socket.close();

       }

      

// Part B will also need you to implement

// private static methods sendBytes and contentType

// Your part B code above will be using these private methods

      

}

Explanation / Answer

and the Client

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote