Exemplo n.º 1
0
        // 这个channelId是由CreateAcceptChannelId生成的
        public static void OnAccept(this NetInnerComponent self, long channelId, IPEndPoint ipEndPoint)
        {
            Session session = EntityFactory.CreateWithParentAndId <Session, AService>(self, channelId, self.Service);

            session.RemoteAddress = ipEndPoint;
            //session.AddComponent<SessionIdleCheckerComponent, int, int, int>(NetThreadComponent.checkInteral, NetThreadComponent.recvMaxIdleTime, NetThreadComponent.sendMaxIdleTime);
        }
Exemplo n.º 2
0
        // 这个channelId是由CreateAcceptChannelId生成的
        public static void OnAccept(this NetKcpComponent self, long channelId, IPEndPoint ipEndPoint)
        {
            Session session = EntityFactory.CreateWithParentAndId <Session, AService>(self, channelId, self.Service);

            session.RemoteAddress = ipEndPoint;

            session.AddComponent <SessionAcceptTimeoutComponent>();
            // 客户端连接,2秒检查一次recv消息,10秒没有消息则断开
            session.AddComponent <SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);
        }
Exemplo n.º 3
0
        public static Session Create(this NetKcpComponent self, IPEndPoint realIPEndPoint)
        {
            long    channelId = RandomHelper.RandInt64();
            Session session   = EntityFactory.CreateWithParentAndId <Session, AService>(self, channelId, self.Service);

            session.RemoteAddress = realIPEndPoint;
            session.AddComponent <SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);

            self.Service.GetOrCreate(session.Id, realIPEndPoint);

            return(session);
        }
Exemplo n.º 4
0
        private static Session CreateInner(this NetInnerComponent self, long channelId, IPEndPoint ipEndPoint)
        {
            Session session = EntityFactory.CreateWithParentAndId <Session, AService>(self, channelId, self.Service);

            session.RemoteAddress = ipEndPoint;

            self.Service.GetOrCreate(channelId, ipEndPoint);

            //session.AddComponent<InnerPingComponent>();
            //session.AddComponent<SessionIdleCheckerComponent, int, int, int>(NetThreadComponent.checkInteral, NetThreadComponent.recvMaxIdleTime, NetThreadComponent.sendMaxIdleTime);

            return(session);
        }
Exemplo n.º 5
0
        private static ActorLocationSender GetOrCreate(this ActorLocationSenderComponent self, long id)
        {
            if (id == 0)
            {
                throw new Exception($"actor id is 0");
            }

            if (self.Children.TryGetValue(id, out Entity actorLocationSender))
            {
                return((ActorLocationSender)actorLocationSender);
            }

            actorLocationSender = EntityFactory.CreateWithParentAndId <ActorLocationSender>(self, id);
            return((ActorLocationSender)actorLocationSender);
        }