socket.setKeepAlive([enable][, initialDelay])


启用/禁用保持活动功能,并可选择在空闲套接字上发送第一个保持活动探测之前设置初始延迟。

设置 initialDelay(以毫秒为单位)以设置接收到的最后一个数据包和第一个保持活动探测之间的延迟。 将 0 设置为 initialDelay 将使该值与默认(或先前)设置保持不变。

启用保持活动功能将设置以下套接字选项:

  • SO_KEEPALIVE=1
  • TCP_KEEPIDLE=initialDelay
  • TCP_KEEPCNT=10
  • TCP_KEEPINTVL=1

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