当前位置:编程学习 > C#/ASP.NET >>

如何取消已经被绑定的连接,释放端口出来啊?附代码.

如何取消已经被绑定的连接,释放端口出来啊?



while (true)
            {   trysockerr = false;
                Thread.Sleep(50);
                try
                {    
                    sock.Bind(ipep);

                }
                catch
                {
                    trysockerr = true;
                }
                sock.Close();//这里不是释放了吗?为什么不行??请高手制教.
            Console.WriteLine(trysockerr);
           
          //  Listener.ReceiveFrom(aaa,ref ep);

            if (trysockerr)
            {
                byte[] aaa = new byte[58];
                Socket Listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                Listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                Listener.Bind(ipep);
                Listener.SendTo(aaa, ipep2);
            }
              
            } --------------------编程问答-------------------- 简单点可以不用管下面的if语句:
试过了,就第一个是false,其他的一直都是true,证明端口并没有释放出来,请高手解决一下这个问题,先谢啦.~
            while (true)
            {   trysockerr = false;
                Thread.Sleep(50);
                try
                {    
                    sock.Bind(ipep);

                }
                catch
                {
                    trysockerr = true;
                }
                sock.Close();
            Console.WriteLine(trysockerr);
                } --------------------编程问答-------------------- up 大家帮帮忙吧,我一直在等答案... --------------------编程问答-------------------- How to release the port of TCP Client immediately when the connection is disconnect with the TCP server. - TCP 客户端与 TCP 服务器断开连接后,如何立刻释放端口

http://blog.csdn.net/HackerJLY/archive/2011/01/05/6116857.aspx
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,