An example of a TCP listener on localhost that will log the message if written to and close the connection if connected to.
const decoder = new TextDecoder();const listener = Deno.listen({
hostname: "127.0.0.1",
port: 8080,
transport: "tcp",
});for await (const conn of listener) { const buf = new Uint8Array(1024); console.log("Server - received: ", decoder.decode(buf));Run this example locally using the Deno CLI:
deno run -N https://docs.deno.com/examples/scripts/tcp_listener.ts