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

Usage in Deno

```typescript import { Socket } from "node:node__net.d.ts"; ```
Socket.prototype.setTimeout(
timeout: number,
callback?: () => void,
): this
Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket. By default `net.Socket` do not have a timeout. When an idle timeout is triggered the socket will receive a `'timeout'` event but the connection will not be severed. The user must manually call `socket.end()` or `socket.destroy()` to end the connection. ```js socket.setTimeout(3000); socket.on('timeout', () => { console.log('socket timeout'); socket.end(); }); ``` If `timeout` is 0, then the existing idle timeout is disabled. The optional `callback` parameter will be added as a one-time listener for the `'timeout'` event.

Parameters

timeout: number
optional
callback: () => void

Return Type

this
The socket itself.