From 8083295c42366d2e04067db92531382310802bc7 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 4 Nov 2022 16:11:30 -0500 Subject: [PATCH] Pretending to get started --- 6.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 6.ts diff --git a/6.ts b/6.ts new file mode 100644 index 0000000..3539d13 --- /dev/null +++ b/6.ts @@ -0,0 +1,31 @@ +import { BufReader } from "https://deno.land/std@0.157.0/io/buffer.ts"; + +const PORT = 5588; + +// const tEnc = new TextEncoder(); + +console.log(`Starting TCP listener on on 0.0.0.0:${PORT}`); + +function chatSession(conn: Deno.Conn) { + const closeOnDisconnect = () => { + console.warn("Disconnected client"); + try { + conn.close(); + } catch (err) { + console.error("Error closing client connection:", err); + } + }; + + serve(conn).catch((e) => e).finally(closeOnDisconnect); +} + +async function serve(conn: Deno.Conn) { + const reader = new BufReader(conn); + reader.peek(1); +} + +for await (const conn of Deno.listen({ port: PORT })) { + console.log("Connection established:", conn.remoteAddr); + chatSession(conn); + console.log("Connection closed:", conn.remoteAddr); +}