This commit is contained in:
Holly Stubbs 2024-01-18 19:56:18 +00:00
parent 01af433838
commit 21a088820b
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E

View file

@ -118,13 +118,16 @@ if (process.argv[2] === "server") {
process.exit(1);
}
const config:IClientConfig = JSON.parse(readFileSync("./config/client-config.json").toString());
let CLIENT_ID = 0;
const server = createServer((socket) => {
let authed = false;
let queuedMessages = new Array<Buffer>();
let txBytes = 0;
let rxBytes = 0;
const thisClientId = CLIENT_ID++;
console.log(`[LOCAL CLIENT ${thisClientId}] New Connection`);
const txrxInterval = setInterval(() => {
console.log(`TX: ${(txBytes / 1024).toFixed(2)}KB/s | RX: ${(rxBytes / 1024).toFixed(2)}KB/s`);
console.log(`[LOCAL CLIENT ${thisClientId}] TX: ${(txBytes / 1024).toFixed(2)}KB/s | RX: ${(rxBytes / 1024).toFixed(2)}KB/s`);
txBytes = rxBytes = 0;
}, 1000);
@ -171,6 +174,7 @@ if (process.argv[2] === "server") {
function clientCloseOrError() {
socket.end();
clearInterval(txrxInterval);
console.log(`[LOCAL CLIENT ${thisClientId}] Remote server terminated the connection.`);
}
client.on("close", clientCloseOrError);
client.on("error", clientCloseOrError);
@ -188,6 +192,7 @@ if (process.argv[2] === "server") {
function serverCloseOrError() {
client.close();
clearInterval(txrxInterval);
console.log(`[LOCAL CLIENT ${thisClientId}] Disconnected`);
}
socket.on("close", serverCloseOrError);
socket.on("error", serverCloseOrError);