Skip to content

Instantly share code, notes, and snippets.

@RealYukiSan
Last active April 11, 2024 09:57
Show Gist options
  • Save RealYukiSan/e0feea6d8fbf1b0963bab570e5828d57 to your computer and use it in GitHub Desktop.
Save RealYukiSan/e0feea6d8fbf1b0963bab570e5828d57 to your computer and use it in GitHub Desktop.
gwrok keep-alive
const net = require('node:net');
function keepAlive(ephPort, intervalId) {
const socket = new net.Socket();
socket.setTimeout(1000);
socket.connect(port, process.env.GWROK_IP, () => socket.destroy());
// stop the interval, indicate either the gwrok server no longer accept request
// or just bad internet connection and should retry if this is the case.
// for now we not perform retry, just stop the interval.
socket.on('timeout', () => {
clearInterval(intervalId);
});
}
const intervalId = setInterval(
() => keepAlive(ephPort, intervalId),
1000 * process.env.KEEPALIVE_TIMEOUT
);
#!/bin/sh
# The script will prevent the gwrok client from closing the connection after 5 minutes of inactivity.
# usage:
# - start gwrok client first:
# setsid ./gwrok client <client parameter> &>/tmp/gwrok-http.log </dev/null
# - start the keep-alive:
# setsid ./keep-alive.sh <ip> <port> &>/tmp/gwrok-http.log </dev/null
while :;do printf 'GET / HTTP/1.1\r\nHost: $1\r\n\r\n' | nc $1 $2;sleep 4m;done
@RealYukiSan
Copy link
Author

RealYukiSan commented Mar 23, 2024

for keep-alive ssh service: while :;do nc -d -N <ip> <port>;sleep 5;done

-d: disable stdin
-N: immediately exit after connect

@RealYukiSan
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment