Esempio n. 1
0
        /// <summary>
        /// 连接到远程终端
        /// </summary>
        /// <param name="remoteEndPoint">远程ip和端口</param>
        /// <exception cref="AuthenticationException"></exception>
        /// <returns></returns>
        public virtual async Task <SocketError> ConnectAsync(EndPoint remoteEndPoint)
        {
            var error = await this.ConnectInternalAsync(remoteEndPoint);

            if (error == SocketError.Success)
            {
                await this.session.AuthenticateAsync();

                session.LoopReceiveAsync();
            }

            this.OnConnected(error);
            return(error);
        }
Esempio n. 2
0
        /// <summary>
        /// 启动会话循环接收
        /// </summary>
        /// <param name="session">会话</param>
        private async void LoopReceiveAsync(TcpSessionBase session)
        {
            // 通知插件会话已连接
            var context = this.CreateContext(session);

            if (this.plugManager.RaiseConnected(this, context) == false)
            {
                return;
            }

            try
            {
                await session.AuthenticateAsync().ConfigureAwait(false);

                if (this.plugManager.RaiseAuthenticated(this, context))
                {
                    session.LoopReceiveAsync();
                }
            }
            catch (Exception ex)
            {
                this.plugManager.RaiseException(this, ex);
                this.ReuseSession(session);
            }
        }