예제 #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}");
         }
     }
 }
예제 #2
0
        private static void StartHttpsServer(ServerConfig serverConfig)
        {
            try
            {
                foreach (var port in serverConfig.port_list)
                {
                    Task.Run(async() =>
                    {
                        var server = new HttpServer(new ServerOption()
                        {
                            Ip           = "Any",
                            Port         = port,
                            ProtocolType = ProtocolType.Tcp,
                            BackLog      = 100,
                            NoDelay      = true,
                            Security     = serverConfig.is_ssl ? SslProtocols.Tls12 : SslProtocols.None,
                            SslServerAuthenticationOptions = serverConfig.is_ssl ? new SslServerAuthenticationOptions
                            {
                                EnabledSslProtocols = SslProtocols.Tls12,
                                ServerCertificate   = new X509Certificate2(string.IsNullOrEmpty(serverConfig.certfile) ? GlobalConfig.CertFile : serverConfig.certfile, string.IsNullOrEmpty(serverConfig.certpwd) ? GlobalConfig.CertPassword : serverConfig.certpwd)
                            } : null
                        });

                        var res = await server.StartAysnc();
                        if (res)
                        {
                            HttpServerList.Add(server);
                            LogHelper.Info($"{serverConfig.protocol}服务启动成功,监听端口:{port}");
                        }
                        else
                        {
                            LogHelper.Error($"{serverConfig.protocol}服务启动失败,监听端口:{port}");
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error($"{serverConfig.protocol}服务初始化失败,端口:{serverConfig.port},{ex}");
            }
        }
예제 #3
0
        private static void StartHttpServer(ServerConfig serverConfig)
        {
            try
            {
                foreach (var port in serverConfig.port_list)
                {
                    var server = new HttpServer(port)
                    {
                        NATServer = NATServer
                    };
                    server.Start();
                    HttpServerList.Add(server);
                }

                HandleLog.WriteLine($"{serverConfig.protocol}服务启动成功,监听端口:{serverConfig.port}");
            }
            catch (Exception ex)
            {
                HandleLog.WriteLine($"{serverConfig.protocol}服务初始化失败,端口:{serverConfig.port},{ex}");
            }
        }