cs654/lab3 partA finished
git-svn-id: svn://anubis/gvsu@4 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
7a22188417
commit
a82373c0fe
BIN
cs654/lab3/partA/HttpRequest.class
Normal file
BIN
cs654/lab3/partA/HttpRequest.class
Normal file
Binary file not shown.
53
cs654/lab3/partA/HttpRequest.java
Normal file
53
cs654/lab3/partA/HttpRequest.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
BIN
cs654/lab3/partA/WebServer.class
Normal file
BIN
cs654/lab3/partA/WebServer.class
Normal file
Binary file not shown.
30
cs654/lab3/partA/WebServer.java
Normal file
30
cs654/lab3/partA/WebServer.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user