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?
close() call shuts down the socket associated with the socket descriptor socket, and frees resources allocated to the socket. If socket refers to an open TCP connection, the connection is closed. If a stream socket is closed when there is input data queued, the TCP connection is reset rather than being cleanly closed.
// make a connection with the user from server side io. on('connection', (socket)=>{ console. log('New user connected'); }); Similarly, from the client-side, we need to add a script file and then make a connection to a server through which users send data to a server.
Use the *CANCEL,TCP command to stop the connection to a node or on a socket.
If you want to close the connection in a timely fashion, call shutdown() before close(). The "bad file description" error means (most likely) that the socket is already closed (at least from Python side).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With