socket.setTimeout(timeout[, callback])
timeout
<number>callback
<Function>- 返回: <net.Socket> 套接字自身
将套接字设置为在套接字上 timeout
毫秒不活动后超时。
默认情况下 net.Socket
没有超时。
当空闲超时被触发时,套接字将收到 'timeout'
事件,但连接不会被切断。
用户必须手动调用 socket.end()
或 socket.destroy()
才能结束连接。
socket.setTimeout(3000);
socket.on('timeout', () => {
console.log('socket timeout');
socket.end();
});
如果 timeout
为 0,则禁用现有空闲超时。
可选的 callback
参数将被添加为 'timeout'
事件的单次监听器。
timeout
<number>callback
<Function>- 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.