package net.zephyrizing.http_server;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class HttpServer {
    public static void main(String[] args) throws Exception {
        int portNumber = Integer.parseInt(args[0]);
        System.err.println("Starting server on port " + args[0]);

        try (ServerSocket listenSocket = new ServerSocket(portNumber)) {
            System.err.println("Listening for clients...");

            try (Socket socket = listenSocket.accept();
                 PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
                 BufferedReader in = new BufferedReader(
                     new InputStreamReader(socket.getInputStream()));
                 BufferedReader stdIn = new BufferedReader(
                     new InputStreamReader(System.in))) {
                System.err.println("Connected to client. Proceeding to echo...");

                String clientInput;
                while ((clientInput = in.readLine()) != null) {
                    System.out.println("Got: "+clientInput);
                    out.println("Echo: "+clientInput);
                }
            }
        }
    }
}

@@ -293,37 +293,146 @@
 mber
- = Integer.parseInt(args%5B0%5D);
+;%0A        if (args.length == 1) %7B%0A         portNumber = Integer.parseInt(args%5B0%5D);%0A        %7D else %7B%0A            portNumber = 80;%0A        %7D
 %0A   
@@ -484,23 +484,26 @@
 ort %22 + 
-args%5B0%5D
+portNumber
 );%0A%0A    
@@ -1077,35 +1077,61 @@
 ent.
- Proceeding to echo...%22
+%22);%0A%0A                String request = in.readLine(
 );%0A
-%0A
     
@@ -1152,219 +1152,429 @@
 ring
- clientInput;%0A                while ((clientInput = in.readLine()) != null) %7B%0A                    System.out.println(%22Got: %22+clientInput);%0A                    out.println(%22Echo: %22+clientInput);%0A                %7D
+%5B%5D params = request.split(%22 %22);%0A%0A                assert(params.length == 3);%0A%0A                String method = params%5B0%5D;%0A                String path = params%5B1%5D;%0A                String protocolVersion = params%5B2%5D;%0A%0A                System.out.format(%22Client requested to %25s file %25s over %25s.%5Cn%22,%0A                                  method, path, protocolVersion);%0A                out.format(%22%25s 200 OK%5Cr%5Cn%22, protocolVersion);
 %0A   

Implement a very basic http server