From 95cee1853769c170c2c265ab9367a7e3083b5ee9 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Tue, 11 Oct 2022 13:39:54 -0500 Subject: [PATCH] Fix 0 and 1 --- 0.ts | 4 ++++ 1.ts | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/0.ts b/0.ts index c6e2233..f464778 100644 --- a/0.ts +++ b/0.ts @@ -5,6 +5,10 @@ const PORT = 5588; console.log(`Listening on port ${PORT}`); for await (const conn of Deno.listen({ port: PORT })) { + echo(conn); +} + +async function echo(conn: Deno.Conn) { await copy(conn, conn); conn.close(); } diff --git a/1.ts b/1.ts index e4b57b6..2ee7c58 100644 --- a/1.ts +++ b/1.ts @@ -6,6 +6,10 @@ const tEnc = new TextEncoder(); console.log(`Listening on port ${PORT}`); for await (const conn of Deno.listen({ port: PORT })) { + processRequestStream(conn); +} + +async function processRequestStream(conn: Deno.Conn) { console.log("Connection established:", conn.remoteAddr); try { for await (const request of requests(conn)) { @@ -25,10 +29,10 @@ for await (const conn of Deno.listen({ port: PORT })) { prime: isPrime(request.number), }; console.debug("Response:", response); - await conn.write(tEnc.encode(JSON.stringify(response) + "\n")); + conn.write(tEnc.encode(JSON.stringify(response) + "\n")); } else { console.debug("Request malformed"); - await conn.write(tEnc.encode("Malformed!\n")); + conn.write(tEnc.encode("Malformed!\n")); } } } catch (e) {