Esempio n. 1
0
        static void Main(string[] args)
        {
            #region 1、日志,配置,建立Socket,监听端口
            BaseProgram.PubMain1(ServerType, m_Port);
            #endregion

            #region 2、连接事件
            Thread mThread = new Thread(ListenClientCallBack);
            mThread.Start();
            #endregion

            #region 连接其他服务器
            GateClientManager.Start();

            #endregion

            #region 主循环
            while (true)
            {
                Thread.CurrentThread.Join(10);
                try
                {
                    ServerHeartbeat.Heartbeat();
                }
                catch (Exception ex)
                {
                    Loger.Error($"服务器错误{ex}");
                }
            }
            #endregion
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            BaseProgram.PubMain1(args, EServerType.网关);

            #region 启动服务器后执行服务器数据初始化

            OnServerStart();

            #endregion 启动服务器后执行服务器数据初始化

            #region  务器事件

            //新连接事件
            BaseServerInfo.AppServer.NewSessionConnected += new SessionHandler <LunarSession>(Dispatcher.OnSessionConnected);

            //连接断开事件
            BaseServerInfo.AppServer.SessionClosed += new SessionHandler <LunarSession, CloseReason>(Dispatcher.OnSessionClosed);

            //收到消息事件
            BaseServerInfo.AppServer.NewRequestReceived += new RequestHandler <LunarSession, LunarRequestInfo>(Dispatcher.OnDispatch);

            #endregion  务器事件

            BaseProgram.PubMain2();

            BaseProgram.PubMain3();


            #region 连接到其他服务器

            if (!GateServerLinkManager.Start())
            {
                loger.Fatal("连接到其他服务器失败");
            }

            #endregion 连接到其他服务器

            #region 添加读取指令的线程

            BaseServerInfo.threadDriverCmds = new Thread(new ThreadStart(DriverCmds.ThreadDriverCmds));
            BaseServerInfo.threadDriverCmds.Start();
            Thread.Sleep(1000);

            #endregion 添加读取指令的线程

            #region 添加发送消息线程

            BaseServerInfo.threadSend = new Thread(new ThreadStart(BaseDispatch.ThreadSendMain));
            BaseServerInfo.threadSend.Start();
            Thread.Sleep(1000);


            #endregion

            #region 进入主循环

            while (true)
            {
                System.Threading.Thread.CurrentThread.Join(BaseServerInfo.ServerHeartbeat);
                try
                {
                    ServerHeartbeat.Heartbeat();
                }
                catch (Exception ex)
                {
                    loger.Fatal("服务器错误", ex);
                }
            }

            #endregion 进入主循环
        }