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 {

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 dont 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

}

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!