plexer
This commit is contained in:
parent
08902abf97
commit
8d2567cb5a
46
tcplexer.ts
46
tcplexer.ts
|
@ -1,6 +1,40 @@
|
|||
import { copy } 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");
|
||||
for await (const conn of listener) {
|
||||
copy(conn, conn).finally(() => conn.close());
|
||||
}
|
||||
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);
|
||||
}
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue