deno/tests/testdata/echo_server.ts
2024-07-25 15:30:28 +10:00

13 lines
375 B
TypeScript

import { copy } from "@std/io/copy";
const addr = Deno.args[0] || "0.0.0.0:4544";
const [hostname, port] = addr.split(":");
const listener = Deno.listen({ hostname, port: Number(port) });
console.log("listening on", addr);
listener.accept().then(
async (conn) => {
console.log("received bytes:", await copy(conn, conn));
conn.close();
listener.close();
},
);