A Simple Server
public static void main(String [] args) throws Exception {
ServerSocket server = new ServerSocket(8080) ;
Socket sock = server.accept() ;
BufferedReader in = new BufferedReader(
new InputStreamReader(sock.getInputStream()) ;
String header = in.readLine() ;
. . . skip over any other lines in request packet . . .
String fileName = getFileName(header) ; // Second field of header
byte [] bytes = readFile(“.” + fileName) ; // Contents of local file
new DateOutputStream(sock.getOutputStream()) ;
if( . . . ) { // File exists and is a .html file
out.writeBytes(“HTTP/1.0 200 OK\r\n”) ;
out.writeBytes(“Content-Length: ” + bytes.length + “\r\n”) ;
out.writeBytes(“Content-Type: text/html\r\n\r\n”) ;