Exemple #1
0
        static void InitSocket()
        {
            var simpleCfg = IocUnity.Get <SimpleSocketConfig>();

            Stopwatch startWatch = new Stopwatch();

            startWatch.Start();
            simpleCfg.Mode = CSuperSocket.SocketBase.SocketMode.Udp;
            var bootstrap = BootstrapFactory.CreateBootstrapFromServerCfg(simpleCfg);

            startWatch.Stop();
            Console.WriteLine("CSpuerTcp初始化工厂耗时:{0}ms", startWatch.ElapsedMilliseconds);

            startWatch.Reset();
            startWatch.Start();
            var isSuccess = bootstrap.Initialize();

            startWatch.Stop();
            Console.WriteLine("CSpuerTcp启动耗时:{0}ms", startWatch.ElapsedMilliseconds);
            if (!isSuccess)
            {
                SetConsoleColor(ConsoleColor.Red);
                Console.WriteLine("Failed to initialize CSuperSocket ServiceEngine! Please check error log for more information!");
                Console.ReadKey();
                return;
            }
            _server = bootstrap.AppServers.ToList().FirstOrDefault() as Service;
            Console.WriteLine("Starting...");
            var result = bootstrap.Start();

            Console.WriteLine("监听端口:{0}", simpleCfg.Port);
            Console.WriteLine("-------------------------------------------------------------------");
            SetConsoleColor(ConsoleColor.Green);
            //Console.WriteLine($"上位机唯一Id:{ConfigurationManager.AppSettings["Pid"].ToString()}");
        }