diff --git a/simples/JT808.Gateway.SimpleServer/Program.cs b/simples/JT808.Gateway.SimpleServer/Program.cs index ab18d21..c7975db 100644 --- a/simples/JT808.Gateway.SimpleServer/Program.cs +++ b/simples/JT808.Gateway.SimpleServer/Program.cs @@ -1,22 +1,22 @@ -using JT808.Gateway.Abstractions.Enums; -using JT808.Gateway.ReplyMessage; +using System; +using System.Threading.Tasks; +using JT808.Gateway.Abstractions; +using JT808.Gateway.Abstractions.Configurations; +using JT808.Gateway.Abstractions.Enums; using JT808.Gateway.MsgLogging; +using JT808.Gateway.ReplyMessage; using JT808.Gateway.SessionNotice; +using JT808.Gateway.SimpleServer.Impl; +using JT808.Gateway.SimpleServer.Services; +using JT808.Gateway.Transmit; using JT808.Protocol; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using System; -using System.Threading.Tasks; -using JT808.Gateway.SimpleServer.Impl; -using JT808.Gateway.SimpleServer.Services; -using JT808.Gateway.Abstractions; -using JT808.Gateway.Transmit; -using Microsoft.AspNetCore.Hosting; -using JT808.Gateway.Abstractions.Configurations; -using Microsoft.AspNetCore.Builder; namespace JT808.Gateway.SimpleServer { @@ -24,45 +24,24 @@ namespace JT808.Gateway.SimpleServer { static void Main(string[] args) { - var builder = WebApplication.CreateBuilder(); - builder.Host.ConfigureAppConfiguration((hostingContext, config) => - { - config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory); - config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); - }) - .ConfigureLogging((context, logging) => - { - logging.AddConsole(); - }) - .ConfigureServices((hostContext, services) => - { - services.AddSingleton(); - services.AddSingleton(typeof(ILogger<>), typeof(Logger<>)); + var builder = WebApplication.CreateBuilder(args); + builder.Services.AddSingleton() + .AddSingleton(typeof(ILogger<>), typeof(Logger<>)) //使用内存队列实现会话通知 - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddJT808Configure() - .AddGateway(hostContext.Configuration) - .AddMessageHandler() - .AddMsgLogging() - .AddSessionNotice() - .AddTransmit(hostContext.Configuration) - .AddTcp() - .AddUdp() - .Builder(); - }); + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddJT808Configure() + .AddGateway(builder.Configuration) + .AddMessageHandler() + .AddMsgLogging() + .AddSessionNotice() + .AddTransmit(builder.Configuration) + .AddTcp() + .AddUdp() + .Builder(); - builder.WebHost.UseKestrel((app, serverOptions) => - { - //1.配置webapi端口监听 - var jT808Configuration = app.Configuration.GetSection(nameof(JT808Configuration)).Get(); - serverOptions.ListenAnyIP(jT808Configuration.WebApiPort); - }) - .ConfigureServices((hostContext, services) => - { - services.AddControllers(); - }); + builder.Services.AddControllers(); var app = builder.Build(); app.UseRouting(); app.MapControllers(); diff --git a/simples/JT808.Gateway.SimpleServer/appsettings.json b/simples/JT808.Gateway.SimpleServer/appsettings.json index 8e97a06..a686bdf 100644 --- a/simples/JT808.Gateway.SimpleServer/appsettings.json +++ b/simples/JT808.Gateway.SimpleServer/appsettings.json @@ -11,8 +11,9 @@ "JT808Configuration": { "TcpPort": 808, "UdpPort": 808, - "WebApiPort": 828, - "WebApiToken": "123456" + "WebApiToken": "123456", + "TcpReaderIdleTimeSeconds":30, + "TcpReceiveTimeoutCheckTimeSeconds":1 }, "RemoteServerOptions": { "DataTransfer": [