Esempio n. 1
0
        public void OnAccept(AChannel channel)
        {
            Console.WriteLine("OnAccept:" + Thread.CurrentThread.ManagedThreadId);
            Session session = ComponentFactory.CreateWithParent <Session, NetworkComponent, AChannel>(this, this, channel);

            this.sessions.Add(session.Id, session);
        }
        public void OnAccept(AChannel channel)
        {
            Session session = new Session(this, channel);

            this.sessions.Add(session.Id, session);
            session.Start();
        }
Esempio n. 3
0
        /// <summary>
        /// 所有连接到服务器的客户端的会话 都会从这个方法中得到
        /// </summary>
        /// <param name="channel">Channel.</param>
        public void OnAccept(AChannel channel)
        {
            Session session = ComponentFactory.CreateWithParent <Session, AChannel>(this, channel);

            this.sessions.Add(session.Id, session);
            session.Start();
        }
Esempio n. 4
0
        public Session(ComponentNetwork aNetwork, AChannel aChannel, Action <bool> OnConnnect = null)
        {
            this.network = aNetwork;
            this.channel = aChannel;
            long id = this.Id = IdGenerater.GenerateId();

            channel.ClearAction <AChannel, int>(channel.errorCallback);
            channel.ErrorCallback += (c, e) =>
            {
                if (OnConnnect != null)
                {
                    OnConnnect(false);
                    OnConnnect = null;
                }
                this.network.Remove(id);
            };

            channel.ClearAction <AChannel, int>(channel.errorCallback);
            channel.ConnnectCallback += (c) =>
            {
                if (OnConnnect != null)
                {
                    OnConnnect(true);
                    OnConnnect = null;
                }
            };

            channel.ClearAction <MemoryStream>(channel.readCallback);
            channel.ReadCallback += this.OnRead;

            componentNetMsg = this.network.entity.GetComponent <ComponentNetMsg>();
        }
Esempio n. 5
0
        /// <summary>
        /// 创建一个新Session
        /// </summary>
        public Session Create(IPEndPoint ipEndPoint)
        {
            AChannel channel = this.Service.ConnectChannel(ipEndPoint);
            Session  session = ComponentFactory.CreateWithParent <Session, AChannel>(this, channel);

            this.sessions.Add(session.Id, session);
            return(session);
        }
Esempio n. 6
0
        /// <summary>
        /// 创建一个新Session
        /// </summary>
        public Session Create(string address)
        {
            AChannel channel = this.Service.ConnectChannel(address);
            Session  session = ComponentFactory.CreateWithParent <Session, AChannel>(this, channel);

            this.sessions.Add(session.Id, session);
            return(session);
        }
Esempio n. 7
0
        public override Session OnAccept(AChannel channel)
        {
            Session session = base.OnAccept(channel);

            // 内网accept连接,一分钟检查一次,20分钟没有收到消息则断开, 主要是防止连接过来的机器宕机,导致无法超时主动断开,这里检测时间是连接方的两倍
            session.AddComponent <SessionIdleCheckerComponent, int, int, int>(60 * 1000, 1000 * 60 * 20, int.MaxValue);
            return(session);
        }
Esempio n. 8
0
        public virtual Session OnAccept(AChannel channel)
        {
            Session session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel);

            this.Sessions.Add(session.Id, session);
            channel.Start();
            return(session);
        }
        /// <summary>
        /// 创建一个新Session
        /// </summary>
        public Session Create(string address)
        {
            AChannel channel = this.Service.ConnectChannel(address);
            Session  session = new Session(this, channel);

            this.sessions.Add(session.Id, session);
            session.Start();
            return(session);
        }
Esempio n. 10
0
 public override void Dispose()
 {
     base.Dispose();
     if (this.channel != null)
     {
         this.channel.Dispose();
         this.channel = null;
     }
 }
Esempio n. 11
0
        public void Awake(AChannel aChannel)
        {
            this.channel = aChannel;
            this.requestCallback.Clear();
            long id = this.Id;

            channel.ErrorCallback += (c, e) => { this.Network.Remove(id); };
            channel.ReadCallback  += this.OnRead;
        }
Esempio n. 12
0
        public KChannel GetKChannel(long id)
        {
            AChannel aChannel = this.GetChannel(id);

            if (aChannel == null)
            {
                return(null);
            }
            return((KChannel)aChannel);
        }
Esempio n. 13
0
        public virtual async Task <Session> Accept()
        {
            AChannel channel = await this.Service.AcceptChannel();

            Session session = ComponentFactory.CreateWithId <Session, NetworkComponent, AChannel>(IdGenerater.GenerateId(), this, channel);

            session.Parent         = this;
            channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
            this.sessions.Add(session.Id, session);
            return(session);
        }
Esempio n. 14
0
        /// <summary>
        /// 创建一个新Session
        /// </summary>
        public Session Create(IPEndPoint ipEndPoint, Action <bool> OnConnnect = null)
        {
            if (this.Service == null)
            {
                return(null);
            }
            AChannel channel = this.Service.ConnectChannel(ipEndPoint);
            Session  session = new Session(this, channel, OnConnnect);

            this.sessions.Add(session.Id, session);
            session.Start();
            return(session);
        }
Esempio n. 15
0
        public void Awake(AChannel aChannel)
        {
            this.channel = aChannel;
            this.requestCallback.Clear();
            long id = this.Id;

            //错误回调  会在NetworkComponent中报错并移除这个会话Session
            channel.ErrorCallback += (c, e) =>
            {
                this.Network.Remove(id);
            };
            channel.ReadCallback += this.OnRead;              //收到网络通讯数据回调
        }
Esempio n. 16
0
 public void Awake(NetworkComponent net, AChannel aChannel)
 {
     this.Error   = 0;
     this.channel = aChannel;
     this.requestCallback.Clear();
     //Log.Debug("唤醒");
     channel.ErrorCallback += (c, e) =>
     {
         Log.Debug("移除:" + e);
         this.Error = e;
         this.Network.Remove(this.Id);
     };
     channel.ReadCallback += this.OnRead;
 }
Esempio n. 17
0
        public void Awake(AChannel aChannel)
        {
            //缓存通道
            this.channel = aChannel;
            this.requestCallback.Clear();
            long id = this.Id;

            //错误回调
            channel.ErrorCallback += (c, e) =>
            {
                this.Network.Remove(id);
            };
            //注册通道读取消息的回调 由通道内部触发
            channel.ReadCallback += this.OnRead;
        }
Esempio n. 18
0
        public void Awake(AChannel aChannel)
        {
            this.channel = aChannel;
            this.requestCallback.Clear();
            long id = this.Id;

            channel.ErrorCallback += (c, e) =>
            {
                if (this.Network != null) //[MyAppend]
                {                         //[MyAppend]
                    this.Network.Remove(id);
                }//[MyAppend]
            };
            channel.ReadCallback += this.OnRead;
        }
Esempio n. 19
0
        public void Awake(AChannel aChannel)
        {
            this.Error   = 0;
            this.channel = aChannel;
            this.requestCallback.Clear();

            channel.ErrorCallback += (c, e) =>
            {
                this.Error = e;
                this.Network.Remove(this.Id);
            };
            channel.ReadCallback += this.OnRead;

            this.channel.Start();
        }
Esempio n. 20
0
        /// <summary>
        /// 创建一个Session
        /// </summary>
        public Session Create(string address)
        {
            //这里以TCP为例注释:
            //TCP的话 是调用TService的ConnectChannel 内部进行构建一个TChannel
            //注意:TChannel是对Socket的第一层封装,包括:连接、接收、发送、构建报文、拆解报文...为外部提供Socket交互的接口
            AChannel channel = this.Service.ConnectChannel(address);
            //创建session会话实体 将自身作为session的父物体 并且把TChannel传递进去
            Session session = ComponentFactory.CreateWithParent <Session, AChannel>(this, channel);

            //注意:框架会调用到session的Awake方法,并且将TChannel传递给Awake方法,然后才继续往下执行
            //管理该会话实体
            this.sessions.Add(session.Id, session);
            //调用会话实体的Start方法
            session.Start();
            return(session);
        }
Esempio n. 21
0
        public Session(AChannel channel)
        {
            this.channel = channel;

            long timeNow = TimeHelper.Now();

            this.LastRecvTime = timeNow;
            this.LastSendTime = timeNow;

            long id = this.Id;

            this.channel.ErrorCallback += (c, e) =>
            {
                OzNetClient.Instance.DispatchClose(this, e);
            };
            this.channel.ReadCallback += OnRead;
        }
Esempio n. 22
0
 /// <summary>
 /// 创建一个新Session
 /// </summary>
 public virtual Session Create(IPEndPoint ipEndPoint)
 {
     try
     {
         AChannel channel = this.Service.ConnectChannel(ipEndPoint);
         Session  session = ComponentFactory.CreateWithId <Session, NetworkComponent, AChannel>(IdGenerater.GenerateId(), this, channel);
         session.Parent         = this;
         channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
         this.sessions.Add(session.Id, session);
         return(session);
     }
     catch (Exception e)
     {
         Log.Error(e);
         return(null);
     }
 }
Esempio n. 23
0
        public void Awake(AChannel aChannel)
        {
            long timeNow = TimeHelper.Now();

            this.LastRecvTime = timeNow;
            this.LastSendTime = timeNow;

            this.channel = aChannel;
            this.requestCallback.Clear();
            long id = this.Id;

            channel.ErrorCallback += (c, e) =>
            {
                this.Network.Remove(id);
            };
            channel.ReadCallback += this.OnRead;
        }
Esempio n. 24
0
        public static void Output(IntPtr bytes, int count, IntPtr user)
        {
            if (Instance == null)
            {
                return;
            }
            AChannel aChannel = Instance.GetChannel((uint)user);

            if (aChannel == null)
            {
                Debug.LogError($"not found kchannel, {(uint)user}");
            }

            KChannel kChannel = aChannel as KChannel;

            kChannel.Output(bytes, count);
        }
Esempio n. 25
0
        public /*static*/ void Output(IntPtr bytes, int count, IntPtr user)
        {
            //if (Instance == null)
            //{
            //	return;
            //}
            AChannel aChannel = /*Instance.*/ GetChannel((uint)user);

            if (aChannel == null)
            {
                Log.Error($"not found kchannel, {(uint)user}");
                return;
            }

            KChannel kChannel = aChannel as KChannel;

            kChannel.Output(bytes, count);
        }
Esempio n. 26
0
        public void Awake(AChannel aChannel)
        {
            this.channel = aChannel;
            this.requestCallback.Clear();
            long id = this.Id;

            channel.ErrorCallback += (c, e) =>
            {
                this.Network.Remove(id);
            };
            channel.ReadCallback += this.OnRead;
            if (ETModel.Game.Scene.GetComponent <LatencyComponent>() == null)
            {
                mLatencyComponent = ETModel.Game.Scene.AddComponent <LatencyComponent>();
            }
            else
            {
                mLatencyComponent = ETModel.Game.Scene.GetComponent <LatencyComponent>();
            }
            this.channel.Start();
        }
Esempio n. 27
0
 protected void OnAccept(AChannel channel)
 {
     this.acceptCallback.Invoke(channel);
 }
Esempio n. 28
0
 public void Awake(NetworkComponent net, AChannel c)
 {
     this.Error   = 0;
     this.channel = c;
     this.requestCallback.Clear();
 }