Keep SSH session alive.
This commit is contained in:
@@ -178,7 +178,16 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible, setIsNoAuthHidde
|
||||
}
|
||||
});
|
||||
|
||||
const pingInterval = setInterval(() => {
|
||||
socketRef.current.emit("ping");
|
||||
}, 5000);
|
||||
|
||||
socketRef.current.on("pong", () => {
|
||||
console.log("Received pong from server.");
|
||||
});
|
||||
|
||||
return () => {
|
||||
clearInterval(pingInterval);
|
||||
if (terminalInstance.current) {
|
||||
terminalInstance.current.dispose();
|
||||
terminalInstance.current = null;
|
||||
|
||||
@@ -53,7 +53,7 @@ io.on("connection", (socket) => {
|
||||
.on("ready", function () {
|
||||
logger.info("SSH connection established");
|
||||
|
||||
conn.shell({ term: "xterm-256color" }, function (err, newStream) {
|
||||
conn.shell({ term: "xterm-256color", keepaliveInterval: 30000 }, function (err, newStream) {
|
||||
if (err) {
|
||||
logger.error("Shell error:", err.message);
|
||||
socket.emit("error", err.message);
|
||||
@@ -93,6 +93,9 @@ io.on("connection", (socket) => {
|
||||
logger.error("Error:", err.message);
|
||||
socket.emit("error", err.message);
|
||||
})
|
||||
.on("ping", function () {
|
||||
socket.emit("ping");
|
||||
})
|
||||
.connect({
|
||||
host: ip,
|
||||
port: port,
|
||||
@@ -102,7 +105,9 @@ io.on("connection", (socket) => {
|
||||
algorithms: {
|
||||
kex: ['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256'],
|
||||
serverHostKey: ['ssh-ed25519', 'ecdsa-sha2-nistp256']
|
||||
}
|
||||
},
|
||||
keepaliveInterval: 30000,
|
||||
keepaliveCountMax: 3,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user