コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }