Exemple #1
0
 private static void StartWebServer(Common.Models.ServerConfig serverConfig)
 {
     if (serverConfig.port_list.Any())
     {
         var server = new HttpAppServer()
         {
             ServerConfig = serverConfig
         };
         bool setup = server.Setup(new RootConfig()
         {
             DisablePerformanceDataCollector = true
         }, new CSuperSocket.SocketBase.Config.ServerConfig()
         {
             Listeners = from s in serverConfig.port_list
                         select new ListenerConfig
             {
                 Ip   = "Any",
                 Port = s
             },            //批量监听
             TextEncoding            = "ASCII",
             MaxRequestLength        = 102400,
             MaxConnectionNumber     = 1000,
             ReceiveBufferSize       = 102400,
             SendBufferSize          = 102400,
             LogBasicSessionActivity = true,
             LogAllSocketException   = true,
             SyncSend    = false,
             Security    = serverConfig.ssl_type == null ? null : Enum.GetName(typeof(ssl_type), serverConfig.ssl_type),
             Certificate = serverConfig.ssl_type == null ? null : new CertificateConfig()
             {
                 FilePath = string.IsNullOrEmpty(serverConfig.certfile) ? CertFile : serverConfig.certfile,
                 Password = string.IsNullOrEmpty(serverConfig.certpwd) ? CertPassword : serverConfig.certpwd,
                 ClientCertificateRequired = false
             },
             DisableSessionSnapshot  = true,
             SessionSnapshotInterval = 1
         });
         if (setup)
         {
             var start = server.Start();
             if (start)
             {
                 server.NewSessionConnected += WebServer_NewSessionConnected;
                 server.NewRequestReceived  += WebServer_NewRequestReceived;
                 server.SessionClosed       += WebServer_SessionClosed;
                 HttpServerList.Add(server);
                 HandleLog.WriteLine($"{serverConfig.protocol}服务启动成功,监听端口:{serverConfig.port}");
             }
             else
             {
                 HandleLog.WriteLine($"{serverConfig.protocol}服务启动失败,端口:{serverConfig.port}");
             }
         }
         else
         {
             HandleLog.WriteLine($"{serverConfig.protocol}服务初始化失败,端口:{serverConfig.port}");
         }
     }
 }
Exemple #2
0
 private static void StartWebServer()
 {
     if (GlobalConfig.WebPortList.Any())
     {
         HttpServer = new HttpAppServer();
         bool setup = HttpServer.Setup(new RootConfig()
         {
             DisablePerformanceDataCollector = true
         }, new ServerConfig()
         {
             Listeners = from s in GlobalConfig.WebPortList
                         select new ListenerConfig
             {
                 Ip   = "Any",
                 Port = s
             },            //批量监听
             TextEncoding            = "ASCII",
             MaxRequestLength        = 102400,
             MaxConnectionNumber     = 1000,
             ReceiveBufferSize       = 102400,
             SendBufferSize          = 102400,
             LogBasicSessionActivity = true,
             LogAllSocketException   = true,
             SyncSend = false,
             //Security = "tls12",
             //Certificate = new CertificateConfig()
             //{
             //    FilePath = CertFile,
             //    Password = CertPassword,
             //    ClientCertificateRequired = false
             //},
             DisableSessionSnapshot  = true,
             SessionSnapshotInterval = 1
         });
         if (setup)
         {
             var start = HttpServer.Start();
             if (start)
             {
                 HttpServer.NewSessionConnected += WebServer_NewSessionConnected;
                 HttpServer.NewRequestReceived  += WebServer_NewRequestReceived;
                 HttpServer.SessionClosed       += WebServer_SessionClosed;
                 HandleLog.WriteLine($"Web服务启动成功,监听端口:{GlobalConfig.WebPort}");
             }
             else
             {
                 HandleLog.WriteLine($"Web服务启动失败,端口:{GlobalConfig.WebPort}");
             }
         }
         else
         {
             HandleLog.WriteLine($"Web服务初始化失败,端口:{GlobalConfig.WebPort}");
         }
     }
 }