RT。采用C#求解决方案目前server的socket主动close之后,listening没了。但是还有2个ES状态。说明服务器只是关闭了监听,但是客户端的连接没有主动close。

解决方案 »

  1.   

     private bool Connect_Utils()
            {
                bool flag = true;
                try
                {
                    if (serverProxy == null || serverProxy.State != CommunicationState.Opened)
                    {
                        NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
                        binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
                        binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                        binding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
                        binding.TransferMode = TransferMode.Buffered;
                        binding.TransactionFlow = false;
                        binding.TransactionProtocol = TransactionProtocol.OleTransactions;                    binding.MaxBufferPoolSize = 2147483647;
                        binding.MaxBufferSize = 2147483647;
                        binding.MaxConnections = 32;
                        binding.MaxReceivedMessageSize = 2147483647;
                        binding.ReaderQuotas.MaxArrayLength = 2147483647;
                        string addr = "net.tcp://192.168.1.2:9000/server";
                        serverProxy = new ServerProxy(new InstanceContext(this), binding, new EndpointAddress(addr));
                        serverProxy.Open();//打开服务
                        flag = true;
                    }
                }
                catch (Exception Ex)
                {
                    MessageBox.Show("连接服务器时发生错误" + Ex.Message, "连接提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    flag = false;
                }
                return flag;
            }
    以上为连接服务
    以下为关闭服务if(serverProxy == null || serverProxy.State != CommunicationState.Opened)
    {
       serverProxy.Close();
    }
      

  2.   

    http://blog.csdn.net/fengyarongaa/article/details/6631953
      

  3.   

    可能我描述的有问题或不太清楚。我的意思是我是server端。
    Listen之后,一直在等待客户端连接(同步短连接)现在服务器在运行,我想手工停止server服务器,现在的程序是listen是停止了,客户端肯定是连接不上来了。
    但是之前已经连接的客户端,只要客户端没主动关闭,还是可以直接发送接收数据,因为连接的状态为ESTABLISHED状态。我的问题是服务器主动关闭后,要求lister停止,并关闭所有已经连接的客户端(服务器主动关闭客户端的连接)