Log more
This commit is contained in:
parent
01af433838
commit
21a088820b
1 changed files with 6 additions and 1 deletions
7
index.ts
7
index.ts
|
@ -118,13 +118,16 @@ if (process.argv[2] === "server") {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const config:IClientConfig = JSON.parse(readFileSync("./config/client-config.json").toString());
|
const config:IClientConfig = JSON.parse(readFileSync("./config/client-config.json").toString());
|
||||||
|
let CLIENT_ID = 0;
|
||||||
const server = createServer((socket) => {
|
const server = createServer((socket) => {
|
||||||
let authed = false;
|
let authed = false;
|
||||||
let queuedMessages = new Array<Buffer>();
|
let queuedMessages = new Array<Buffer>();
|
||||||
let txBytes = 0;
|
let txBytes = 0;
|
||||||
let rxBytes = 0;
|
let rxBytes = 0;
|
||||||
|
const thisClientId = CLIENT_ID++;
|
||||||
|
console.log(`[LOCAL CLIENT ${thisClientId}] New Connection`);
|
||||||
const txrxInterval = setInterval(() => {
|
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;
|
txBytes = rxBytes = 0;
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
@ -171,6 +174,7 @@ if (process.argv[2] === "server") {
|
||||||
function clientCloseOrError() {
|
function clientCloseOrError() {
|
||||||
socket.end();
|
socket.end();
|
||||||
clearInterval(txrxInterval);
|
clearInterval(txrxInterval);
|
||||||
|
console.log(`[LOCAL CLIENT ${thisClientId}] Remote server terminated the connection.`);
|
||||||
}
|
}
|
||||||
client.on("close", clientCloseOrError);
|
client.on("close", clientCloseOrError);
|
||||||
client.on("error", clientCloseOrError);
|
client.on("error", clientCloseOrError);
|
||||||
|
@ -188,6 +192,7 @@ if (process.argv[2] === "server") {
|
||||||
function serverCloseOrError() {
|
function serverCloseOrError() {
|
||||||
client.close();
|
client.close();
|
||||||
clearInterval(txrxInterval);
|
clearInterval(txrxInterval);
|
||||||
|
console.log(`[LOCAL CLIENT ${thisClientId}] Disconnected`);
|
||||||
}
|
}
|
||||||
socket.on("close", serverCloseOrError);
|
socket.on("close", serverCloseOrError);
|
||||||
socket.on("error", serverCloseOrError);
|
socket.on("error", serverCloseOrError);
|
||||||
|
|
Loading…
Reference in a new issue