Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();


            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }
            var result = bootstrap.Start();

            Console.WriteLine("Start result: {0}!", result);
            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }


            /**
             * var appServer = new AMAppServer();
             * if (!appServer.Setup(8080))
             * {
             *  Console.WriteLine("Failed to setup!");
             *  Console.ReadKey();
             *  return;
             * }
             * Console.WriteLine();
             * if (!appServer.Start())
             * {
             *  Console.WriteLine("Failed to start!");
             *  Console.ReadKey();
             *  return;
             * }**/

            Console.WriteLine("Press key 'q' to stop it!");
            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }
            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();
            //appServer.Stop();


            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
		/// <summary>
		/// 初始化服务
		/// </summary>
		private void InitServer()
		{
			Bootstrap = BootstrapFactory.CreateBootstrap();
			
			if (Bootstrap.Initialize())
			{
				RefreshServerInfoList();
			}
		}
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("{0} -> Check TempData DB status ...", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            SQLiteHelper.CreateLocalDB("TempData");
            Console.WriteLine("{0} -> Check GatewayData Table In TempData...", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            SQLiteHelper.CreateTempDataTable("TempData");
            Console.WriteLine("{0} -> Finish TempData DB and GatewayData Table Checked.", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));

            //Console.WriteLine("{0} -> Press any key to start the server!", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));

            //Console.ReadKey();
            //Console.WriteLine();

            var bootstrap = BootstrapFactory.CreateBootstrap();


            if (!bootstrap.Initialize())
            {
                Console.WriteLine("{0} -> Failed to initialize!", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            Console.WriteLine("{1} -> Start result: {0}!", result, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));

            if (result == StartResult.Failed)
            {
                Console.WriteLine("{0} -> Failed to start!", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                Console.ReadKey();
                return;
            }



            while (true)
            {
                Thread.Sleep(1);
            }
            //Console.WriteLine("Press key 'q' to stop it!");

            //while (Console.ReadKey().KeyChar != 'q')
            //{
            //    Console.WriteLine();
            //    continue;
            //}

            //Console.WriteLine();


            //Stop the appServer
            //bootstrap.Stop();

            //Console.WriteLine("{0} -> The server was stopped!", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            //Console.ReadKey();
        }
Exemplo n.º 4
0
        static void RunAsConsole()
        {
            IBootstrap bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize SuperSocket server! Please check error log for more information!");
                return;
            }

            var result = bootstrap.Start();

            foreach (var server in bootstrap.AppServers)
            {
                if (server.IsRunning)
                {
                    Console.WriteLine("- {0} has been started", server.Name);
                }
                else
                {
                    Console.WriteLine("- {0} failed to start", server.Name);
                }
            }

            switch (result)
            {
            case (StartResult.None):
                Console.WriteLine("No server is configured, please check you configuration!");
                break;

            case (StartResult.Success):
                Console.WriteLine("The server engine has been started!");
                break;

            case (StartResult.Failed):
                Console.WriteLine("Failed to start the server engine! Please check error log for more information!");
                break;

            case (StartResult.PartialSuccess):
                Console.WriteLine("Some server instances were started successfully, but the others failed to start! Please check error log for more information!");
                break;
            }

            Console.WriteLine("Press key 'q' to stop the server engine.");

            while (Console.ReadKey().Key != ConsoleKey.Q)
            {
                Console.WriteLine();
                continue;
            }

            bootstrap.Stop();

            Console.WriteLine();
            Console.WriteLine("The server engine has been stopped!");
        }
Exemplo n.º 5
0
 public MyBootstrap()
 {
     _bootstrap = BootstrapFactory.CreateBootstrap();
     _bootstrap.Initialize();
     _bootstrap.Start();
     //if (_bootstrap.Initialize()) TraceLog.WriteLine("Initialize");
     //else { TraceLog.WriteLine("Initialize failed"); return; }
     //var result = _bootstrap.Start();
     //TraceLog.WriteLine("Start " + result.ToString());
 }
Exemplo n.º 6
0
        public ServiceManager()
        {
            m_Bootstrap = BootstrapFactory.CreateBootstrap();

            if (!m_Bootstrap.Initialize())
            {
                LoggerManager.Log(ELoggerType.Error, "SuperSocket 初始化失败");
                return;
            }
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("请按任何键启动区域指挥中心平台!");
            Console.ReadKey();
            Console.WriteLine();
            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("初始化失败!");
                Console.ReadKey();
                return;
            }

            #region 加载基础设备或通信模块
            try
            {
                SerialCOMManager.CreateInstance();
                Console.WriteLine("串口设备初始化完成");
                HikSdkManager hiksdk = HikSdkManager.CreateInstance();
                Console.WriteLine("海康SDK初始化完成");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
                return;
            }
            #endregion

            var result = bootstrap.Start();

            Console.WriteLine("服务正在启动: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("服务启动失败!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("服务启动成功,请按'q'停止服务!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            //停止服务
            // appServer.Stop();
            bootstrap.Stop();
            Console.WriteLine("服务已停止!");
            Console.ReadKey();
        }
Exemplo n.º 8
0
 /// <summary>
 /// 初始化服务器
 /// </summary>
 private bool SetupAppServer()
 {
     m_Bootstrap = BootstrapFactory.CreateBootstrap();
     if (!m_Bootstrap.Initialize())
     {
         txtMsg.AppendRichText($"{DateTime.Now}>> 初始化服务器配置文件失败,请检查.{Environment.NewLine}", new Font("微软雅黑", 9), Color.Crimson);
         return(false);
     }
     txtMsg.AppendRichText($"{DateTime.Now}>> 初始化服务器配置成功.{Environment.NewLine}", new Font("微软雅黑", 9), Color.FromArgb(2, 79, 142));
     return(true);
 }
Exemplo n.º 9
0
 private void btnStartStop_Click(object sender, EventArgs e)
 {
     if (btnStartStop.Text == "启动服务")
     {
         bootstrap = BootstrapFactory.CreateBootstrap();
         if (!bootstrap.Initialize())
         {
             ServiceStatus = false;
             MessageBox.Show("Failed to initialize!");
             return;
         }
         else
         {
             StartResult result = bootstrap.Start();
             if (result == StartResult.Failed)
             {
                 ServiceStatus = false;
             }
             else if (result == StartResult.Success)
             {
                 var transferServer = bootstrap.GetServerByName("TransferServer") as TransferServer;
                 transferServer.NewSessionConnected += transferServer_NewSessionConnected;
                 transferServer.SessionClosed       += transferServer_SessionClosed;
                 var userServer = bootstrap.GetServerByName("UserServer") as UserServer;
                 userServer.UserJoin     += userServer_UserJoin;
                 userServer.UserLeave    += userServer_UserLeave;
                 userServer.SendToServer += userServer_UserSendToServer;
                 userServer.UserWhisper  += userServer_UserWhisper;
                 userServer.Broadcast    += userServer_UserBroadcast;
                 ServiceStatus            = true;
             }
             else
             {
                 //MessageBox.Show(string.Format("Start result: {0}!", result));
             }
             this.lblStatus.Text = result.ToString();
         }
     }
     else
     {
         bootstrap.Stop();
         ServiceStatus       = false;
         this.lblStatus.Text = "The server was stopped!";
     }
     if (ServiceStatus)
     {
         btnStartStop.Text = "停止服务";
     }
     else
     {
         btnStartStop.Text = "启动服务";
     }
 }
Exemplo n.º 10
0
        public BusServer()
        {
            // Load the server configuration from app.config
            // This is needed to ensure the server is only
            // broadcasting and accepting connectiosn on 127.0.0.1
            // for security.
            var bootstrap = BootstrapFactory.CreateBootstrap();

            bootstrap.Initialize();
            bootstrap.Start();
            Socket = bootstrap.AppServers.FirstOrDefault() as WebSocketServer;
        }
        /// <summary>
        /// 初始化Socket服务
        /// <code>
        /// SocketServiceContainer.Create(CurrentAddinConfiguration);
        /// </code>
        /// </summary>
        /// <param name="currentAddinConfig"></param>
        public static void Create(System.Configuration.Configuration currentAddinConfig)
        {
            IConfigurationSource configSource = currentAddinConfig.GetSection(SocketSection.SectionName) as IConfigurationSource;

            if (configSource == null)
            {
                return;
            }
            IBootstrap bootstrap = BootstrapFactory.CreateBootstrap(configSource);

            bootstrap.Initialize(new Log4NetLogFactory());
            StartResult result = bootstrap.Start();
        }
Exemplo n.º 12
0
        protected IConfigurationSource CreateBootstrap(string configFile, out IBootstrap newBootstrap)
        {
            var fileMap  = new ExeConfigurationFileMap();
            var filePath = Path.Combine(@"Config", configFile);

            fileMap.ExeConfigFilename = filePath;
            var config       = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            var configSource = config.GetSection("superSocket") as IConfigurationSource;

            newBootstrap = BootstrapFactory.CreateBootstrap(configSource);

            return(configSource);
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();

            IBootstrap bootstrap = null;

            try {
                bootstrap = BootstrapFactory.CreateBootstrap();
            } catch (System.Configuration.ConfigurationErrorsException ex) {
                Console.WriteLine(ex.Message);
                Environment.Exit(-1);
            }

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }


            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start server!");

            Console.ReadKey();
            Console.WriteLine();
            Console.WriteLine("Starting...");

            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize SuperSocket server! Please check error log for more information!");
                return;
            }

            var result = bootstrap.Start();

            switch (result)
            {
            case (StartResult.None):
                Console.WriteLine("No server is configured, please check you configuration!");
                break;

            case (StartResult.Success):
                Console.WriteLine("The server has been started!");
                break;

            case (StartResult.Failed):
                Console.WriteLine("Failed to start SuperSocket server! Please check error log for more information!");
                break;

            case (StartResult.PartialSuccess):
                Console.WriteLine("Some server instances were started successfully, but the others failed to start! Please check error log for more information!");
                break;
            }

            Console.WriteLine("Press key 'q' to stop the server.");

            while (Console.ReadKey().Key != ConsoleKey.Q)
            {
                Console.WriteLine();
                continue;
            }

            bootstrap.Stop();

            Console.WriteLine();
            Console.WriteLine("The server has been stopped!");
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                System.Console.WriteLine("Failed to initialize!");
                System.Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            System.Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                System.Console.WriteLine("Failed to start!");
                System.Console.WriteLine(result);
                System.Console.ReadKey();
                return;
            }
            else
            {
                foreach (var appServer in bootstrap.AppServers)
                {
                    var a = System.Console.ForegroundColor;
                    System.Console.ForegroundColor = ConsoleColor.Green;
                    System.Console.WriteLine("{0,20}\t{1,-4}", appServer.Name, appServer.State);
                    System.Console.ForegroundColor = a;
                }
            }

            System.Console.WriteLine("Press key 'q' to stop it!");

            while (System.Console.ReadKey().KeyChar != 'q')
            {
                System.Console.WriteLine();
                continue;
            }

            System.Console.WriteLine();

            //GameStop the appServer
            bootstrap.Stop();

            System.Console.WriteLine("The server was stopped!");

            System.Console.Read();
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");
            Console.ReadKey();
            Console.WriteLine();

            var bootstrap = BootstrapFactory.CreateBootstrap();

            try
            {
                if (!bootstrap.Initialize())
                {
                    Console.WriteLine("Failed to initialize!");
                    Console.ReadKey();
                    return;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            var result = bootstrap.Start();

            Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
        }
Exemplo n.º 17
0
 protected override void OnStart(string[] args)
 {
     // TODO: 在此处添加代码以启动服务。
     m_Websocketserver = BootstrapFactory.CreateBootstrap();
     if (!m_Websocketserver.Initialize())
     {
         Careysoft.Basic.Public.Log.ErrorWrite("Failed to initialize!");
         return;
     }
     (m_Websocketserver.AppServers.First() as MessageServer.Server.MessageSocketServer).EventMessageSocketServer += new Model.EventMessageServerHandler(EventReceiveMessageServer);
     if (m_Websocketserver.Start() == SuperSocket.SocketBase.StartResult.Failed)
     {
         Careysoft.Basic.Public.Log.ErrorWrite("Failed to start!");
     }
 }
Exemplo n.º 18
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                m_labelStatus.Text = "失败";
                return;
            }
            var result = bootstrap.Start();

            m_labelStatus.Text = "服务启动成功";


            RefreshData();
        }
        private static void bootstrap()
        {
            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Program.Exit("Supersocket  initlialize failed!");
            }
            var result = bootstrap.Start();

            Console.WriteLine("Start result: {0}!", result);
            if (result == StartResult.Failed)
            {
                Program.Exit("Start Socket message service failed!");
            }
        }
Exemplo n.º 20
0
    static void Main(string[] args)
    {
        TestSqlHelper ts = new LearnSuperSocket.Test.TestSqlHelper();

        ts.Test();

        Console.WriteLine("Press any key to start the server!");

        Console.ReadKey();
        Console.WriteLine();

        var bootstrap = BootstrapFactory.CreateBootstrap();

        if (!bootstrap.Initialize())
        {
            Console.WriteLine("Failed to initialize!");
            Console.ReadKey();
            return;
        }

        var result = bootstrap.Start();

        Console.WriteLine("Start result: {0}!", result);

        if (result == StartResult.Failed)
        {
            Console.WriteLine("Failed to start!");
            Console.ReadKey();
            return;
        }

        Console.WriteLine("Press key 'q' to stop it!");

        while (Console.ReadKey().KeyChar != 'q')
        {
            Console.WriteLine();
            continue;
        }

        Console.WriteLine();

        //Stop the appServer
        bootstrap.Stop();

        Console.WriteLine("The server was stopped!");
        Console.ReadKey();
    }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            Console.WriteLine("start the server!");

            //Console.ReadKey();
            Console.WriteLine();

            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine(bootstrap.GetServerByName("TelnetServer").SessionCount);
                if (Console.ReadKey().KeyChar == 'c')
                {
                    Console.Clear();
                    Console.WriteLine("Press key 'q' to stop it!");
                }
                continue;
            }

            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("The server was stopped!");
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Press any key to start the server!");

            //Console.ReadKey();
            //Console.WriteLine();

            //通过配置启动SuperSocket
            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            foreach (var s in bootstrap.AppServers)
            {
                Console.WriteLine($"{s.Config.Ip}:{s.Config.Port}");
            }
            Console.WriteLine("Press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("The server was stopped!");
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            Console.WriteLine("press any keycode to start this demo");

            Console.ReadKey();
            Console.WriteLine();

            var server = BootstrapFactory.CreateBootstrap();

            //Setup the server
            if (!server.Initialize())
            {
                Console.WriteLine("failed to initialize!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine();

            //Strat the server
            if (server.Start() == StartResult.Failed)
            {
                Console.WriteLine("failed to start the server");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("the server start successfully,press 'q' to stop the server");

            //Emit Session Connected
            //server.NewSessionConnected += Server_NewSessionConnected;
            //Emit RquestReceived
            //server.NewRequestReceived += Server_NewRequestReceived;

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            //Stop the server
            server.Stop();

            Console.WriteLine("the server has been stoped!");
            Console.ReadKey();
        }
Exemplo n.º 24
0
        private void ServerManager_Load(object sender, EventArgs e)
        {
            //var serverConfig = new ServerConfig
            //{
            //    Port = 2012,//set the listening port
            //    Ip = "192.168.10.159"
            //};
            bootstrap = BootstrapFactory.CreateBootstrap();
            if (!bootstrap.Initialize())
            {
                txtMsg.Items.Add("Failed to initialize!");
                //Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            //TelnetServer sss = bootstrap.AppServers.First() as TelnetServer;
            //sss.NewSessionConnected += sss_NewSessionConnected;
            txtMsg.Items.Add(string.Format("Start result: {0}!", result));

            if (result == StartResult.Failed)
            {
                txtMsg.Items.Add("Failed to start!");
                // Console.ReadKey();
                return;
            }
            //if (!appServer.Setup(2012))
            //{
            //    txtMsg.Items.Add("Failed to setup!");
            //    return;
            //}
            appServer = bootstrap.AppServers.First() as ESOPServer;
            appServer.NewSessionConnected += new SessionHandler <ESOPSession>(appServer_NewSessionConnected);
            appServer.NewRequestReceived  += new RequestHandler <ESOPSession, StringRequestInfo>(appServer_NewRequestReceived);
            appServer.SessionClosed       += appServer_SessionClosed;

            //Try to start the appServer
            //if (!appServer.Start())
            //{
            //    txtMsg.Items.Add("Failed to start!");
            //    return;
            //}

            //txtMsg.Items.Add("The server started successfully");
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Press any key to start the server!");

            var m = System.Reflection.Assembly.GetEntryAssembly();


            //Console.ReadKey();
            //Console.WriteLine();

            var bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("The server was stopped!");
        }
Exemplo n.º 26
0
        public void Init()
        {
            //Console.WriteLine("Press any key to start the server!");

            //Console.ReadKey();
            //Console.WriteLine();

            bootstrap = BootstrapFactory.CreateBootstrap();

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("服务器未初始化");
                Console.ReadKey();
                return;
            }
            var result = bootstrap.Start();

            Console.WriteLine("socket服务器启动结果{0}", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("失败!");
                Console.ReadKey();
                return;
            }
            SeverTimer serverTimer = new SeverTimer();

            serverTimer.Init();

            Console.WriteLine("按Q键退出服务器");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("服务器正常停止!");
            Console.ReadKey();
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            var serviceProvider = new ServiceCollection()
                                  .AddTransient <ITest, Test>()
                                  .AddSuperSocketNet()
                                  .BuildServiceProvider();

            var bootstrap = BootstrapFactory.CreateBootstrap(serviceProvider);

            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            Console.WriteLine("Start result: {0}!", result);

            if (result == StartResult.Failed)
            {
                Console.WriteLine("Failed to start!");
                Console.ReadKey();
                return;
            }

            Console.WriteLine("Press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            Console.WriteLine();

            //Stop the appServer
            bootstrap.Stop();

            Console.WriteLine("The server was stopped!");
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to start the server!");

            Console.ReadKey();
            Console.WriteLine();
            var bootstrap = BootstrapFactory.CreateBootstrap();

            Grade["nimas"] = 123;
            Grade["nimei"] = 321;
            gr.Add(new Tuple <string, int>("nimas", 123));
            gr.Add(new Tuple <string, int>("nimas", 123));
            if (!bootstrap.Initialize())
            {
                Console.WriteLine("Failed to initialize!");
                Console.ReadKey();
                return;
            }

            var result = bootstrap.Start();

            Console.WriteLine("Start result: {0}!", result);

            var socketServer = bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals("WSServer")) as WSServer;


            //socketServer.NewMessageReceived += new SessionHandler<WebSocketSession, StringRequestInfo>(socketServer_NewMessageReceived);//添加新消息到达事件
            socketServer.NewSessionConnected += socketServer_NewSessionConnected;//添加新客户端接入事件
            //socketServer.SessionClosed += socketServer_SessionClosed;//添加连接关闭事件

            Console.WriteLine();

            Console.WriteLine("The server started successfully, press key 'q' to stop it!");

            while (Console.ReadKey().KeyChar != 'q')
            {
                Console.WriteLine();
                continue;
            }

            Console.WriteLine();
            Console.WriteLine("The server was stopped!");
        }
Exemplo n.º 29
0
        void StartSuperWebSocketByConfig()
        {
            m_Bootstrap = BootstrapFactory.CreateBootstrap();

            if (!m_Bootstrap.Initialize())
            {
                return;
            }

            var socketServer = m_Bootstrap.AppServers.FirstOrDefault(s => s.Name.Equals("SuperWebSocket")) as WebSocketServer;

            socketServer.NewMessageReceived  += new SessionHandler <WebSocketSession, string>(socketServer_NewMessageReceived);
            socketServer.NewSessionConnected += socketServer_NewSessionConnected;
            socketServer.SessionClosed       += socketServer_SessionClosed;

            m_WebSocketServer = socketServer;

            m_Bootstrap.Start();
        }
Exemplo n.º 30
0
        private IConfigurationSource SetupBootstrap(string configFile)
        {
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();

            fileMap.ExeConfigFilename = Path.Combine(@"Config", configFile);

            var config       = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            var configSource = config.GetSection("socketServer") as IConfigurationSource;

            m_BootStrap = BootstrapFactory.CreateBootstrap(configSource);

            Assert.IsTrue(m_BootStrap.Initialize());

            var result = m_BootStrap.Start();

            Assert.AreEqual(StartResult.Success, result);

            return(configSource);
        }