gvsu/cs654/lab3/WebServer.java
josh 7ec861062f cs654/lab3 part B completed
git-svn-id: svn://anubis/gvsu@5 45c1a28c-8058-47b2-ae61-ca45b979098e
2008-02-03 03:15:11 +00:00

39 lines
1.0 KiB
Java

import java.io.* ;
import java.net.* ;
import java.util.* ;
public final class WebServer
{
private static final int DEFAULT_PORT = 8080;
public static void main(String argv[]) throws Exception
{
// Get the port number from the command line.
int port = (argv.length > 0)
? (new Integer(argv[0])).intValue()
: DEFAULT_PORT;
// 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();
}
}
}