/// <summary> /// 异步接收客户端们的数据 /// </summary> protected void AsycReveiveFrom() { Action t_LoopAsycReveiveFromHandler = () => { while (m_IsLoop) { m_MRE.Reset(); var t_ClientBuffer = new byte[m_BufferSize]; Socket.BeginReceiveFrom(t_ClientBuffer, 0, t_ClientBuffer.Length, SocketFlags.None, ref m_EndPoint, new AsyncCallback(t_Ar => { m_MRE.Set(); EndPoint t_EndPoint = t_Ar.AsyncState as EndPoint; int t_Recv = Socket.EndReceiveFrom(t_Ar, ref t_EndPoint); if (t_Recv > 0) { var t_ClientEndPoint = ClientEndPointList.Find(value => value != null && value.Equals(t_EndPoint)); //检查 if (null != t_ClientEndPoint) //已经存在了这个客户端 { } else //没有这个客户端 { ListHelper.Add <EndPoint>(ClientEndPointList, t_EndPoint); } Read(Socket, t_EndPoint, t_ClientBuffer, t_Recv); //读取数据 } }), m_EndPoint); m_MRE.WaitOne(1000, true); } }; t_LoopAsycReveiveFromHandler.BeginInvoke(new AsyncCallback(t_Ar => { }), null); }