Skip to main content
Socket.prototype.setKeepAlive - node__net.d.ts - Node documentation
method Socket.prototype.setKeepAlive

Usage in Deno

```typescript import { Socket } from "node:node__net.d.ts"; ```
Socket.prototype.setKeepAlive(
enable?: boolean,
initialDelay?: number,
): this
Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket. Set `initialDelay` (in milliseconds) to set the delay between the last data packet received and the first keepalive probe. Setting `0` for`initialDelay` will leave the value unchanged from the default (or previous) setting. Enabling the keep-alive functionality will set the following socket options: * `SO_KEEPALIVE=1` * `TCP_KEEPIDLE=initialDelay` * `TCP_KEEPCNT=10` * `TCP_KEEPINTVL=1`

Parameters

optional
enable: boolean = false
optional
initialDelay: number = 0

Return Type

this
The socket itself.