Exemplo n.º 1
0
        /// <summary>
        /// 处理连接请求
        /// </summary>
        private void ProcessConnected(object obj)
        {
            TChannel             channel = null;
            SocketAsyncEventArgs e       = obj as SocketAsyncEventArgs;
            UserToken            token   = (UserToken)e.UserToken;

            if (e.SocketError == SocketError.Success)
            {
                // 创建频道
                channel = new TChannel();
                channel.InitChannel(e.ConnectSocket, token.PackageParseType);

                // 加入到频道列表
                lock (_allChannels)
                {
                    _allChannels.Add(channel);
                }
            }
            else
            {
                LogSystem.Log(ELogType.Error, $"ProcessConnected error : {e.SocketError}");
            }

            // 回调函数
            if (token.Callback != null)
            {
                token.Callback.Invoke(channel, e.SocketError);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 处理接收请求
        /// </summary>
        private void ProcessAccept(object obj)
        {
            SocketAsyncEventArgs e = obj as SocketAsyncEventArgs;

            if (e.SocketError == SocketError.Success)
            {
                // 创建频道
                TChannel channel = new TChannel();
                channel.InitChannel(e.AcceptSocket, _listenerPackageParseType);

                // 添加频道
                AddChannel(channel);
            }
            else
            {
                LogSystem.Log(ELogType.Error, $"ProcessAccept error : {e.SocketError}");
            }

            // 投递下一个接收请求
            StartAccept(e);
        }