Example #1
0
        /// <summary>
        /// Socket数据接收完成时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnSocketReceiveCompleted(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                byte[] buffer = null;
                if (e.SocketError != System.Net.Sockets.SocketError.Success)
                {
                    Close();
                    _uiContext.Post(OnSocketError, SocketErrorMessage.GetMessage(e.SocketError));
                }
                else if (e.BytesTransferred > 0)
                {
                    buffer = new byte[e.BytesTransferred];
                    Buffer.BlockCopy(e.Buffer, 0, buffer, 0, e.BytesTransferred);
                }

                _socketReceiveHandler.Receive(buffer);

                if (_socket != null && _socket.Connected)
                {
                    _socket.ReceiveAsync(e);
                }
            }
            catch (Exception ex)
            {
                Close();
                _uiContext.Post(OnSocketError, ex.Message);
            }
        }
Example #2
0
 private void OnSendCompleted(object pSender, SocketAsyncEventArgs pArgs)
 {
     if (pArgs.SocketError != System.Net.Sockets.SocketError.Success)
     {
         Close();
         _uiContext.Post(OnSocketError, SocketErrorMessage.GetMessage(pArgs.SocketError));
     }
 }