Checkpoint: KV over TCP
Challenge on lesson: Checkpoint: KV Over TCP
Inside Solution, implement the protocol engine and prove it over loopback:
1. static String handle(String line, java.util.Map<String, String> store) — one
protocol turn: parse the command, mutate/query the store, return the response LINE
(no newline included). Rules: PUT k v → "OK"; GET k → "VALUE v" or "MISSING";
QUIT → "BYE"; anything else (including empty and unknown commands) → "ERR".
PUT with a value containing spaces: store everything after the second token.
2. static int serveOnce(int port) — full loop: open ServerSocket on the port,
accept ONE client, serve handle() per received line (store persists across lines
within the session), write each response with "\n" framing, stop after BYE, close
everything in finally, return the number of protocol turns served. Use a 5s
soTimeout so a wedged client cannot hang the run. Runs in the calling thread —
the TEST connects from the same JVM via loopback.
Difficulty: advanced
Back to lesson: Checkpoint: KV Over TCP