我正在编写一个基于套接字的 C 应用程序,它的行为似乎非常不稳定。
该代码是 TCP 端口 6683 上的标准套接字处理,我知道它以前工作过。我相信最有趣的不是提及源代码,而是 netstat -aon
命令的结果:
当它正常工作时,netstat -aon| 的结果grep 6683
命令是:
TCP 127.0.0.1:6683 127.0.0.1:50888 CLOSE_WAIT 6128
TCP 127.0.0.1:50888 127.0.0.1:6683 FIN_WAIT_2 3764
当它不再工作时,netstat -aon | 的结果grep 6683
命令是:
TCP 127.0.0.1:6683 0.0.0.0:0 LISTENING 7800
有谁知道提到的“netstat”结果的含义,这对套接字处理可能意味着什么,我该怎么做才能返回到给出第一个结果的情况?
谢谢
最佳答案
来自 Microsoft 的支持网站:
FIN_WAIT_2 Indicates that the client just received acknowledgment of the first FIN signal from the server
LISTENING Indicates that the server is ready to accept a connection
CLOSE_WAIT Indicates that the server has received the first FIN signal from the client and the connection is in the process of being closed
根据上面的内容,你知道在你的第一种情况下,服务器已经收到了客户端的 FIN,并且客户端已经收到了向服务器发送 FIN 的 ACK。
但是,在第二种情况下,服务器已准备好接受连接,这对我来说听起来像是您尚未建立 TCP 连接。
在不真正了解您的 C 程序试图做什么的情况下,很难在这里诊断您的问题,但我会查看 netstat 的文档然后从那里开始。
关于c++ - Socket编程, "CLOSE_WAIT"、 "FIN_WAIT_2"和 "LISTENING"呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27820811/