Task: Add keep connection setting when start the client and auto closed old connection if duplicated the host for http tunnel client

This commit is contained in:
Sambo Chea 2022-06-26 18:18:44 +07:00
parent 4d56730241
commit 06d5f0a5bd
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490
2 changed files with 16 additions and 4 deletions

View File

@ -53,6 +53,7 @@ function initClient(options) {
clientEndpoint: clientEndpoint,
serverUrl: serverUrl,
access: options.access,
keep_connection: options.keep_connection || true,
};
const initParams = {
@ -97,6 +98,12 @@ function initClient(options) {
console.log(`${clientLogPrefix} disconnected: ${reason}!`);
});
socket.on("disconnect_exit", (reason) => {
console.log(`${clientLogPrefix} disconnected and exited ${reason}!`);
socket.disconnect();
process.exit(1);
});
socket.on("request", (requestId, request) => {
const isWebSocket = request.headers.upgrade === "websocket";
console.log(`${isWebSocket ? "WS" : request.method}: `, request.path);
@ -278,9 +285,14 @@ program
}
return port;
})
.option("-s, --suffix <string>", "setting suffix for client name")
.option("-a, --access <string>", "setting access type (FREE)", TOKEN_FREE)
.option("-p, --profile <string>", "setting profile name", PROFILE_DEFAULT)
.option("-s, --suffix <string>", "suffix for client name")
.option(
"-k, --keep_connection <boolean>",
"keep connection for client and old connection will be closed",
true
)
.option("-a, --access <string>", "access type (FREE)", TOKEN_FREE)
.option("-p, --profile <string>", "profile name", PROFILE_DEFAULT)
.option("-h, --host <string>", "local host value", "localhost")
.option("-o, --origin <string>", "change request origin")
.action((port, options) => {

View File

@ -1,6 +1,6 @@
{
"name": "@cubetiq/hlt",
"version": "0.0.4",
"version": "0.0.5",
"description": "A lightweight http tunnel client using nodejs and socket.io client",
"main": "client.js",
"bin": {