How to disconnect from tcp socket in NodeJs

mgamer picture mgamer · Feb 8, 2012 · Viewed 61.5k times · Source

I connect to socket server in NodeJs using this command:

client = net.createConnection()

How can I then properly disconnect from the server?

I tried client.end() and even client.destroy()

but when I check the connection status using netstat it shows that the connection is in state FIN_WAIT2.

How can I close and destroy the connection altogether?

Answer

JP Richardson picture JP Richardson · Feb 8, 2012

net.createConnection() returns a Socket object. client.destroy() is what you want to do.

Source: http://nodejs.org/docs/latest/api/net.html#socket.destroy