Example #1
0
 protected virtual void OnReceive(TcpReceiveArgs e)
 {
     e.Client = this;
     if (Package != null)
     {
         Package.Import(e.Data, e.Offset, e.Count);
     }
     else
     {
         if (Receive != null)
         {
             Receive(this, e);
         }
     }
 }
Example #2
0
 private void Receive_Completed(object sender, SocketAsyncEventArgs e)
 {
     try
     {
         if (e.SocketError == SocketError.Success && e.BytesTransferred > 0)
         {
             TcpReceiveArgs tra = new TcpReceiveArgs();
             tra.Data   = e.Buffer;
             tra.Offset = 0;
             tra.Count  = e.BytesTransferred;
             OnReceive(tra);
             BeginReceive();
         }
         else
         {
             mLastError = new Exception(string.Format("socket recieve {0} error {1}", e.BytesTransferred, e.SocketError.ToString()));
             DisConnect();
         }
     }
     catch (Exception e_)
     {
         mLastError = e_;
     }
 }