This commit is contained in:
Daniel Flanagan 2022-06-24 19:19:51 -05:00
parent 08902abf97
commit 8d2567cb5a
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
2 changed files with 40 additions and 6 deletions

0
deno.json Normal file
View file

View file

@ -1,6 +1,40 @@
import { copy } from "https://deno.land/std@0.145.0/streams/conversion.ts"; import { iterateReader } from "https://deno.land/std@0.145.0/streams/conversion.ts";
const listener = Deno.listen({ port: 8080 });
console.log("listening on 0.0.0.0:8080"); const clients: Set<Deno.Conn> = new Set();
for await (const conn of listener) {
copy(conn, conn).finally(() => conn.close()); (async () => {
} try {
const sourceListener = Deno.listen({ port: 8080 });
for await (const source of sourceListener) {
console.info("Source connected from", source.remoteAddr);
for await (const packet of iterateReader(source)) {
clients.forEach((client, _v2, _set) =>
client.write(packet).catch(() => {
console.log(`Client disconnected from`, client.remoteAddr);
clients.delete(client);
})
);
}
console.info(`Source disconnected from`, source.remoteAddr);
}
} catch (err) {
console.error("Error listening for TCP connections on port 8080:", err);
}
})();
(async () => {
try {
const clientsListener = Deno.listen({ port: 8081 });
while (true) {
try {
const conn = await clientsListener.accept();
console.log("Client connected from", conn.remoteAddr);
clients.add(conn);
} catch (err) {
console.error("Error accepting client connection:", err);
}
}
} catch (err) {
console.error("Error listening for TCP connections on port 8081:", err);
}
})();