41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { iterateReader } from "https://deno.land/std@0.145.0/streams/conversion.ts";
|
|
|
|
const clients: Set<Deno.Conn> = new Set();
|
|
|
|
(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);
|
|
}
|
|
})();
|