如何从NodeJ中的TCP套接字断开连接 [英] How to disconnect from tcp socket in NodeJs

查看:139
本文介绍了如何从NodeJ中的TCP套接字断开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令连接到NodeJ中的套接字服务器:

I connect to socket server in NodeJs using this command:

client = net.createConnection()

然后如何正确断开与服务器的连接?

How can I then properly disconnect from the server?

我尝试了client.end()甚至client.destroy()

但是当我使用netstat检查连接状态时,它表明连接处于FIN_WAIT2状态.

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?

推荐答案

net.createConnection()返回Socket对象. client.destroy()是您想要做的.

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

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

这篇关于如何从NodeJ中的TCP套接字断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆