Example #1
0
        private async void EndReceive(SocketAsyncEventArgs e)
        {
            try
            {
                output.Write(new StrBr("Receiving...")).Wait();
                byte[] bytes = await hub.Act(e.Buffer).ConfigureAwait(false);

                AsyncUserToken token = (AsyncUserToken)e.UserToken;
                if (e.SocketError != SocketError.Success)
                {
                    //process error.
                }
                if (e.BytesTransferred > 0)
                {
                    if (!token.Socket.SendAsync(e))
                    {
                        EndSend(e);
                    }
                    ;
                }
            }
            catch (Exception exc)
            {
                output.Write(new ToStr(exc)).Wait();
                if (e.SocketError != SocketError.Success)
                {
                    output.Write(new StrBr("Socket error: " + e.SocketError)).Wait();
                }
                e.Completed -= SocketOp_Completed;
                task.SetException(exc);
                task = null;
            }
        }