import java.io.*; import java.net.*; public class WebServer { public static void main(String args[]) throws Exception { (new Thread() { public void run() { try { Thread.sleep(1000*60*20); System.out.println("Web server shutting down after 20 minute timeout"); System.exit(1); } catch (Exception e) {} } }).start(); int port = Integer.getInteger("port", 8080).intValue(); System.out.println("Listening on port " + port); // Create a ServerSocket to listen on that port. ServerSocket ss = new ServerSocket(port); while (true) { Socket client = ss.accept(); System.out.println("Got connection"); // Get input and output streams to talk to the client from the socket BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); PrintWriter out = new PrintWriter(client.getOutputStream()); // Start sending our reply, using the HTTP 1.0 protocol out.println("HTTP/1.0 200 "); // Version & status code out.println("Content-Type: text/plain"); // The type of data we send out.println(); // End of response headers out.flush(); String request = in.readLine(); out.println("Request is \"" + request + "\""); out.close(); } } }