我的Udp服务端代码如下:
               svrsocket = new UdpClient(new IPEndPoint(IPAddress.Parse(ServerIp), Port));
               IPEndPoint e = new IPEndPoint(IPAddress.Any, 0);
               UdpState s=new UdpState ();
               s.U =svrsocket ;
               s.E =e ;
               _sendmessage = new SendMessage(svrsocket);
               while (true)
               {
                   
                      
                       svrsocket.BeginReceive(new AsyncCallback(RecievData), s);
                       _IsRun = true;
                  
               }
在程序运行后出现如下提示:
异常出错在 svrsocket.BeginReceive(new AsyncCallback(RecievData), s);
异常提示:由于系统缓冲区空间不足或列队已满,不能执行套接字上的操作.

解决方案 »

  1.   

    http://www.java2s.com/Code/CSharp/Network/Udp-Client.htm
      

  2.   

    你使用了BeginReceive这样的异步方法,应该有一个阻止方式,可以考虑使用如下的两个类:System.Threading.AutoResetEvent;
    System.Threading.ManualResetEvent;
      

  3.   

    public virtual void RecievData(IAsyncResult iar)
           {
               UdpClient u = (UdpClient)((UdpState)(iar.AsyncState)).U;           IPEndPoint e = (IPEndPoint)((UdpState)(iar.AsyncState)).E;
               Byte[] msgBuffer = u.EndReceive(iar, ref e);
               if (msgBuffer == null)
               {
                   object o = Formatter.Deserialize(msgBuffer);
                   SendMessages.Send(o, e);               svrsocket.BeginReceive(new AsyncCallback(RecievData), new UdpState(u, new IPEndPoint(IPAddress.Any, 0)));           }
           }
      

  4.   

    3L朋友
    一个阻止方式,可以考虑使用如下的两个类: System.Threading.AutoResetEvent; 
    System.Threading.ManualResetEvent;这样的阻塞方式能细说下吗?
      

  5.   

    为啥我使用AutoResetEvent,ManualResetEvent来控制依然有这个问题呢?