本文介绍了如果端口进入CLOSE_WAIT状态,是否可以终止进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究TcpListener和TcpClient并且相互沟通。

我正确地关闭了与此通信相关的所有对象。如下面的代码:



I am working on TcpListener and TcpClient and communicate with each other succsessfully.
I properly closes all objects related to this communication. like in below code:

string mess = "Alert";
                string caption = "Do you want to close Server and stop Application?";
                DialogResult dlgg = MessageBox.Show(caption, mess, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dlgg == DialogResult.Yes)
                {
                    if (networkStream != null)
                    {
                        networkStream.Close();
                        networkStream.Dispose();
                    }

                    else 
                    {
                       Process currprocess = Process.GetCurrentProcess();
                       currprocess.Kill();
                    }

                    if (this.clientSocket != null)
                    {
                        clientSocket.Close();
                    }
                    else { }

                    this.serverSocket.Stop();
                    
                    msg = "Disconnecting all clients , Server succsessfully Stopped!";
                    message();
                  
                    this.Close();
                    Application.Exit();
                }
                else { }





但是有时端口没有关闭,它进入close_wait状态(因为我发现它使用netstat在cmd.exe中)所以那时我再次启动应用程序并听取相同的端口客户端连接但应用程序说客户端没有连接。并且错误说每个套接字只允许使用一次。所以如果我杀了进程对我的应用程序有好处。或者给我建议来克服这个错误。这是我需要解决的非常重要的错误。



谢谢。



But sometimes port not closes and it goes in close_wait state (as i found it in cmd.exe using "netstat") so at that time if i again start application and listen to same port client get connected but application says client not connected. and error said "only one usage of each socket is permited". so if i kill process is it good for my application.Or give me suggestions to overcome this error. this is the very important error i need to solve.

thanks.

推荐答案



这篇关于如果端口进入CLOSE_WAIT状态,是否可以终止进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:54