diff --git a/cs654/lab3/partA/HttpRequest.class b/cs654/lab3/partA/HttpRequest.class new file mode 100644 index 0000000..13992cb Binary files /dev/null and b/cs654/lab3/partA/HttpRequest.class differ diff --git a/cs654/lab3/partA/HttpRequest.java b/cs654/lab3/partA/HttpRequest.java new file mode 100644 index 0000000..beafaf2 --- /dev/null +++ b/cs654/lab3/partA/HttpRequest.java @@ -0,0 +1,53 @@ +import java.io.* ; +import java.net.* ; +import java.util.* ; + +final class HttpRequest implements Runnable { + final static String CRLF = "\r\n"; + Socket socket; + + // Constructor + public HttpRequest(Socket socket) throws Exception { + this.socket = socket; + } + + // Implement the run() method of the Runnable interface. + public void run() +{ + try { + processRequest(); + } catch (Exception e) { + System.out.println(e); + } + } + + private void processRequest() throws Exception { + // Set up output stream + DataOutputStream os = new DataOutputStream(socket.getOutputStream()); + + // Set up input stream filters. + BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); + + // Get the request line of the HTTP request message. + String requestLine = br.readLine(); + + // 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); +} + + + // Close streams and socket. + os.close(); + br.close(); + socket.close(); + } + +} + diff --git a/cs654/lab3/partA/WebServer.class b/cs654/lab3/partA/WebServer.class new file mode 100644 index 0000000..ad7a277 Binary files /dev/null and b/cs654/lab3/partA/WebServer.class differ diff --git a/cs654/lab3/partA/WebServer.java b/cs654/lab3/partA/WebServer.java new file mode 100644 index 0000000..ff7ca39 --- /dev/null +++ b/cs654/lab3/partA/WebServer.java @@ -0,0 +1,30 @@ +import java.io.* ; +import java.net.* ; +import java.util.* ; + +public final class WebServer { + public static void main(String argv[]) throws Exception { + int port = 8080; + + // Establish the listen socket. + ServerSocket socket = new ServerSocket(port); + + // Process HTTP service requests in an infinite loop. + while (true) { + // Listen for a TCP connection request. + Socket connection = socket.accept(); + + // Construct an object to process the HTTP request message. + HttpRequest request = new HttpRequest(connection); + + // Create a new thread to process the request. + Thread thread = new Thread(request); + + // Start the thread. + thread.start(); + } + } +} + + +