Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/node/net.ts>Socket#setKeepAlive

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
method Socket.prototype.setKeepAlive
import { Socket } from "https://deno.land/std@0.138.0/node/net.ts";

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 forinitialDelay 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

enable: boolean
optional
initialDelay: number

Returns

this

The socket itself.