How to close the tcp connection instance created by node net

var server = net.createServer(function(connection) { 
   console.log("client connected");

   connection.on("end", function() {
      console.log("");
   });

   connection.write("Hello World!\r\n");
    
   connection.pipe(connection);

});

server.listen(8080, function() { 
  console.log("server is listening");
});

now I want to shut down connection manually. What method should I use? I have been looking for it for a long time.

Apr.24,2022

server.cloes ([callback]) , can't I close it?


connection.destroy () can be turned off

Menu