Пример #1
0
 /// <summary>
 /// 处理接收事件
 /// </summary>
 /// <param name="ar">异步调用返回</param>
 private void OnReceive(IAsyncResult ar)
 {
     try
     {
         if (ar.AsyncState is Socket)
         {
             Socket socket = ar.AsyncState as Socket;
             int    len    = socket.EndReceive(ar);
             if (len == 0)
             {
                 if (OnError != null)
                 {
                     OnError.Invoke(this, new Exception("can not read data from socket."));
                 }
             }
             else
             {
                 parser.Add(buffer, len);
                 BeginReceive();
             }
         }
     }
     catch (Exception ex)
     {
         if (OnError != null)
         {
             OnError.Invoke(this, ex);
         }
     }
 }