diff --git a/local.js b/local.js index b23f779..b46d916 100644 --- a/local.js +++ b/local.js @@ -251,9 +251,8 @@ var server = net.createServer(function (connection) { connection.on('end', function () { console.log('local disconnected'); - if (ws) { - ws.terminate(); - } + ws?.terminate(); + server.getConnections(function (err, count) { console.log('concurrent connections:', count); }); @@ -261,9 +260,8 @@ var server = net.createServer(function (connection) { connection.on('error', function (e) { console.log(`local error: ${e}`); - if (ws) { - ws.terminate(); - } + ws?.terminate(); + server.getConnections(function (err, count) { console.log('concurrent connections:', count); }); @@ -272,9 +270,7 @@ var server = net.createServer(function (connection) { connection.setTimeout(timeout, function () { console.log('local timeout'); connection.destroy(); - if (ws) { - ws.terminate(); - } + ws?.terminate(); }); }); diff --git a/server.js b/server.js index ede36be..42d9b90 100644 --- a/server.js +++ b/server.js @@ -170,17 +170,13 @@ wss.on('connection', function (ws) { ws.on('close', function () { console.log('server disconnected'); console.log('concurrent connections:', wss.clients.size); - if (remote) { - remote.destroy(); - } + remote?.destroy(); }); ws.on('error', function (e) { console.warn(`server: ${e}`); console.log('concurrent connections:', wss.clients.size); - if (remote) { - remote.destroy(); - } + remote?.destroy(); }); });