Skip to content

Commit

Permalink
移除端口配置,交由宿主管理
Browse files Browse the repository at this point in the history
  • Loading branch information
yedajiang44 committed Feb 24, 2023
1 parent 8db9b13 commit bcb8bff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 50 deletions.
75 changes: 27 additions & 48 deletions simples/JT808.Gateway.SimpleServer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,47 @@
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
{
class Program
{
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<ILoggerFactory, LoggerFactory>();
services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<ILoggerFactory, LoggerFactory>()
.AddSingleton(typeof(ILogger<>), typeof(Logger<>))
//使用内存队列实现会话通知
services.AddSingleton<JT808SessionService>();
services.AddSingleton<IJT808SessionProducer, JT808SessionProducer>();
services.AddSingleton<IJT808SessionConsumer, JT808SessionConsumer>();
services.AddJT808Configure()
.AddGateway(hostContext.Configuration)
.AddMessageHandler<JT808MessageHandlerImpl>()
.AddMsgLogging<JT808MsgLogging>()
.AddSessionNotice()
.AddTransmit(hostContext.Configuration)
.AddTcp()
.AddUdp()
.Builder();
});
.AddSingleton<JT808SessionService>()
.AddSingleton<IJT808SessionProducer, JT808SessionProducer>()
.AddSingleton<IJT808SessionConsumer, JT808SessionConsumer>()
.AddJT808Configure()
.AddGateway(builder.Configuration)
.AddMessageHandler<JT808MessageHandlerImpl>()
.AddMsgLogging<JT808MsgLogging>()
.AddSessionNotice()
.AddTransmit(builder.Configuration)
.AddTcp()
.AddUdp()
.Builder();

builder.WebHost.UseKestrel((app, serverOptions) =>
{
//1.配置webapi端口监听
var jT808Configuration = app.Configuration.GetSection(nameof(JT808Configuration)).Get<JT808Configuration>();
serverOptions.ListenAnyIP(jT808Configuration.WebApiPort);
})
.ConfigureServices((hostContext, services) =>
{
services.AddControllers();
});
builder.Services.AddControllers();
var app = builder.Build();
app.UseRouting();
app.MapControllers();
Expand Down
5 changes: 3 additions & 2 deletions simples/JT808.Gateway.SimpleServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"JT808Configuration": {
"TcpPort": 808,
"UdpPort": 808,
"WebApiPort": 828,
"WebApiToken": "123456"
"WebApiToken": "123456",
"TcpReaderIdleTimeSeconds":30,
"TcpReceiveTimeoutCheckTimeSeconds":1
},
"RemoteServerOptions": {
"DataTransfer": [
Expand Down

0 comments on commit bcb8bff

Please sign in to comment.