Skip to content

Files

Latest commit

Aug 30, 2017
365b8db · Aug 30, 2017

History

History
26 lines (19 loc) · 711 Bytes

socket_settimeout_timeout_callback.md

File metadata and controls

26 lines (19 loc) · 711 Bytes
  • Returns: {net.Socket} The socket itself.

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.

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.