Force close all connections in a node.js http server

后端 未结 5 1488
被撕碎了的回忆
被撕碎了的回忆 2020-12-28 13:33

I have an http server created using:

var server = http.createServer()

I want to shut down the server. Presumably I\'d do this by calling:

<
5条回答
  •  佛祖请我去吃肉
    2020-12-28 13:53

    You need to

    1. subscribe to the connection event of the server and add opened sockets to an array
    2. keep track of the open sockets by subscribing to their close event and removing the closed ones from your array
    3. call destroy on all of the remaining open sockets when you need to terminate the server

    You also have the chance to run the server in a child process and exit that process when you need.

提交回复
热议问题