socket.ref()


默认情况下,绑定一个套接字会导致只要套接字打开,Node.js 进程就无法退出。可以使用 socket.unref() 方法将套接字从保持 Node.js 进程活跃的引用计数中排除。socket.ref() 方法则会将套接字重新加入引用计数,并恢复默认行为。

【By default, binding a socket will cause it to block the Node.js process from exiting as long as the socket is open. The socket.unref() method can be used to exclude the socket from the reference counting that keeps the Node.js process active. The socket.ref() method adds the socket back to the reference counting and restores the default behavior.】

多次调用 socket.ref() 不会产生额外效果。

【Calling socket.ref() multiples times will have no additional effect.】

socket.ref() 方法返回对套接字的引用,因此可以链式调用。

【The socket.ref() method returns a reference to the socket so calls can be chained.】