public virtual bool Setup(INetServerConfig config, INetApplication application, INetProtocol protocol, ISocketSessionFactory sessionFactory)
        {
            if (protocol == null)
            {
                throw new ArgumentNullException("protocol");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            this.protocol       = protocol;
            this.application    = application;
            this.config         = config;
            this.endPoint       = new IPEndPoint(config.Address, config.Port);
            this.sessionFactory = sessionFactory;

            this.status    = NetServerStatus.Inited;
            this.IsRunning = false;

            return(true);
        }
        public virtual bool Stop()
        {
            if (status == NetServerStatus.Started && serverSocket != null)
            {
                status = NetServerStatus.Stopping;
                serverSocket.Close();

                status = NetServerStatus.Stopped;
            }

            return(true);
        }
        public virtual bool Start()
        {
            if (status == NetServerStatus.Started)
            {
                return(false);
            }

            if (status == NetServerStatus.Uninit)
            {
                throw new InvalidOperationException("服务尚未初始化,无法启动");
            }

            if (status == NetServerStatus.Starting)
            {
                return(false);
            }

            status = NetServerStatus.Starting;
            startupEvent.Reset();

            Thread thread = new Thread(new ThreadStart(() =>
            {
                bool isSuccess = InnerStart();
                if (isSuccess)
                {
                    status = NetServerStatus.Started;
                }
                else
                {
                    status = NetServerStatus.Error;
                }
                startupEvent.Set();
            }));

            thread.IsBackground = true;
            thread.Start();


            startupEvent.WaitOne();

            StartTime = DateTime.Now;

            if (Started != null)
            {
                Started(this, EventArgs.Empty);
            }

            return(status == NetServerStatus.Started);
        }