Skip to content

Instantly share code, notes, and snippets.

@hertzg
Last active September 4, 2024 16:59
Show Gist options
  • Save hertzg/e0eb11d4ca9501ae6b932a9464e5f051 to your computer and use it in GitHub Desktop.
Save hertzg/e0eb11d4ca9501ae6b932a9464e5f051 to your computer and use it in GitHub Desktop.
test
node_modules/
const Net = require('net'),
NetKeepAlive = require('net-keepalive')
// Create a TCP Server
const srv = Net.createServer((s) => {
console.log('Connected %j', s.address())
// Doesn't matter what it does
s.pipe(s)
})
// Start on some port
srv.listen(1337, () => {
console.log('Listening on %j', srv.address())
})
// Connect to that server
const s = Net.createConnection({ port: 1337 }, () => {
console.log('Connected to %j', s.address())
//IMPORTANT: KeepAlive must be enabled for this to work
s.setKeepAlive(true, 1000)
// Set TCP_KEEPINTVL for this specific socket
NetKeepAlive.setKeepAliveInterval(s, 1000)
// Get TCP_KEEPINTVL for this specific socket
NetKeepAlive.getKeepAliveInterval(s) // 1000
// Set TCP_KEEPCNT for this specific socket
NetKeepAlive.setKeepAliveProbes(s, 1)
// Get TCP_KEEPCNT for this specific socket
NetKeepAlive.getKeepAliveProbes(s) // 1
})
Listening on {"address":"::","family":"IPv6","port":1337}
Connected {"address":"::ffff:127.0.0.1","family":"IPv6","port":1337}
Connected to {"address":"127.0.0.1","family":"IPv4","port":46868}
{
"name": "tmp.f5fdyf4v9p",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "tmp.f5fdyf4v9p",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"net-keepalive": "^4.0.6"
}
},
"node_modules/@yuuang/ffi-rs-darwin-arm64": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-arm64/-/ffi-rs-darwin-arm64-1.0.91.tgz",
"integrity": "sha512-7mnetAlSq244bcM0HL+Y+DNBXW/dIlqGJbuQLsutjQUTuNRUpHz92X/ngMAIJfsviabWi+la/deLUPrnkwowsA==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 12"
}
},
"node_modules/@yuuang/ffi-rs-darwin-x64": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-darwin-x64/-/ffi-rs-darwin-x64-1.0.91.tgz",
"integrity": "sha512-n5cGLafp1hCTqbMfi8g74l+dfHqWFrFo+NWdz3kzlkGu5OeBVVS4Q6Jb2lh8kECmQjpohUy6OgSzuv5QWpYfPA==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 12"
}
},
"node_modules/@yuuang/ffi-rs-linux-arm64-gnu": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-gnu/-/ffi-rs-linux-arm64-gnu-1.0.91.tgz",
"integrity": "sha512-TADjoGU0G6T+41sUl+BfV8aqVK70nGk2xS3VfUljhJ2nJQX3aHZTWDXosvAu0dKTldcPcHX8A0sex6WM03zkFw==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 12"
}
},
"node_modules/@yuuang/ffi-rs-linux-arm64-musl": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-arm64-musl/-/ffi-rs-linux-arm64-musl-1.0.91.tgz",
"integrity": "sha512-nO16uoxPY+3CGWKe/QoyjTEkRrtj50AasPlTznNNBYQq06JlMQ8iCIh7086ful2UnYP5NKK/GksuY42FV6e1yQ==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 12"
}
},
"node_modules/@yuuang/ffi-rs-linux-x64-gnu": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-gnu/-/ffi-rs-linux-x64-gnu-1.0.91.tgz",
"integrity": "sha512-Kx4FvgAl1WBZO4DT2G89yZfE7D8ynRMGWx6X3P+FzICkAaKwLz0T+EVJBgypEV+rg5K5UFj84GguulrL5ApGsw==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 12"
}
},
"node_modules/@yuuang/ffi-rs-linux-x64-musl": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-linux-x64-musl/-/ffi-rs-linux-x64-musl-1.0.91.tgz",
"integrity": "sha512-dYxW5SQO3q6f6+9DsmgUtHmwVrbry+iQxnz+TZJWDe7lbSmnzQ9qTGn8yXOjNY5uU1fh7SIYeFDMkjlSDdxg4w==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 12"
}
},
"node_modules/@yuuang/ffi-rs-win32-arm64-msvc": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-arm64-msvc/-/ffi-rs-win32-arm64-msvc-1.0.91.tgz",
"integrity": "sha512-BKtfrutdf+6zT1hW40+ZYot/1XotMoFtw64K9EXZn50CcUCVDukShWHVnjwRNZPn7JXIO23L9GGWLn3VQHyk3g==",
"cpu": [
"arm64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 12"
}
},
"node_modules/@yuuang/ffi-rs-win32-ia32-msvc": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-ia32-msvc/-/ffi-rs-win32-ia32-msvc-1.0.91.tgz",
"integrity": "sha512-DRhGpYv8/tFMpjzCxg8gXECPYYNihpYGz56gylEY9txXIniJOM3We6/UT6/oozqX4b70VMwSemMnLlqDmFJhkA==",
"cpu": [
"x64",
"ia32"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 12"
}
},
"node_modules/@yuuang/ffi-rs-win32-x64-msvc": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/@yuuang/ffi-rs-win32-x64-msvc/-/ffi-rs-win32-x64-msvc-1.0.91.tgz",
"integrity": "sha512-HX9mUB4ykot9MEkLj7W3pwBPOxCsHtQwN0HSx/gSN1oNjbGgL86Ngar41UglswMYv5WH27xeckBWzKpNzMqp4g==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 12"
}
},
"node_modules/ffi-rs": {
"version": "1.0.91",
"resolved": "https://registry.npmjs.org/ffi-rs/-/ffi-rs-1.0.91.tgz",
"integrity": "sha512-B0OscU3Doy/zgD2uqmul/fyni7PgGZJk16pqNryHJTXbXV/y+ydnMjV7jSi6KOprKJZxsbjpiI5Sh9NgvcTqOg==",
"license": "MIT",
"optionalDependencies": {
"@yuuang/ffi-rs-darwin-arm64": "1.0.91",
"@yuuang/ffi-rs-darwin-x64": "1.0.91",
"@yuuang/ffi-rs-linux-arm64-gnu": "1.0.91",
"@yuuang/ffi-rs-linux-arm64-musl": "1.0.91",
"@yuuang/ffi-rs-linux-x64-gnu": "1.0.91",
"@yuuang/ffi-rs-linux-x64-musl": "1.0.91",
"@yuuang/ffi-rs-win32-arm64-msvc": "1.0.91",
"@yuuang/ffi-rs-win32-ia32-msvc": "1.0.91",
"@yuuang/ffi-rs-win32-x64-msvc": "1.0.91"
}
},
"node_modules/net-keepalive": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/net-keepalive/-/net-keepalive-4.0.6.tgz",
"integrity": "sha512-M+e6S1QFhMqNyO+b9tR08vcvVGPKcJ16Okv/CGN5iMthu7N91/HRQjXw4ZmCSAQnuTZS93UXg3VD9o7uG+CXPg==",
"license": "MIT",
"dependencies": {
"ffi-rs": "1.0.91"
},
"engines": {
"node": ">=10.20.0"
}
}
}
}
{
"name": "tmp.f5fdyf4v9p",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"net-keepalive": "^4.0.6"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment