Esempio n. 1
0
 //获取微信Post外网地址
 public static string GetOuterPostAddress()
 {
     if (string.IsNullOrEmpty(outerPostAddressStr))
     {
         ConfigComponent           configComponent           = Game.Scene.GetComponent <ConfigComponent>();
         HttpListenerAddressConfig httpListenerAddressConfig = (HttpListenerAddressConfig)configComponent.Get(typeof(HttpListenerAddressConfig), 0);
         outerPostAddressStr = httpListenerAddressConfig.OuterPostAddress;
     }
     return(outerPostAddressStr);
 }
Esempio n. 2
0
        public void Start()
        {
            MyListerner = new HttpListener();
            while (true)
            {
                try
                {
                    MyListerner.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
                    ConfigComponent           configComponent           = Game.Scene.GetComponent <ConfigComponent>();
                    HttpListenerAddressConfig httpListenerAddressConfig = (HttpListenerAddressConfig)configComponent.Get(typeof(HttpListenerAddressConfig), 0);
                    Log.Debug("服务器地址......" + httpListenerAddressConfig.Address);
                    MyListerner.Prefixes.Add(httpListenerAddressConfig.Address);
                    MyListerner.Start();
                }
                catch (Exception ex)
                {
                    Log.Debug(ex + "服务器启动失败......");
                    break;
                }
                Log.Debug("服务器启动成功......");

                //线程池
                int minThreadNum;
                int portThreadNum;
                int maxThreadNum;
                ThreadPool.GetMaxThreads(out maxThreadNum, out portThreadNum);
                ThreadPool.GetMinThreads(out minThreadNum, out portThreadNum);
                Log.Debug($"最大线程数:{maxThreadNum}");
                Log.Debug($"最小空闲线程数:{minThreadNum}");
                //ThreadPool.QueueUserWorkItem(new WaitCallback(TaskProc1), x);

                Log.Debug("\n等待客户连接中......");
                while (true)
                {
                    //等待请求连接
                    //没有请求则GetContext处于阻塞状态
                    HttpListenerContext ctx = MyListerner.GetContext();

                    ThreadPool.QueueUserWorkItem(new WaitCallback(TaskProc), ctx);
                }
            }
        }