import java.io.* ; import java.net.* ; import java.util.* ; public class DummyServer { public static void main(String [] args) throws Exception { ServerSocket server = new ServerSocket(8080); while (true) { Socket sock = server.accept() ; BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream())); String method = in.readLine(); System.out.println(method) ; int contentLength=0 ; while(true) { String field = in.readLine(); System.out.println(field) ; if(field.length() == 0) break ; if(field.substring(0, 16).equalsIgnoreCase("Content-Length: ")) contentLength = Integer.parseInt(field.substring(16)) ; } for(int i = 0 ; i < contentLength ; i++) { int b = in.read() ; System.out.print((char) b) ; } PrintWriter out = new PrintWriter(new OutputStreamWriter(sock.getOutputStream())); out.println("HTTP/1.0 200 OK"); out.println("Content-Type: text/html"); out.println("") ; out.println("Sorry, nobody is home.") ; out.close() ; } } }