@@ -19,17 +19,29 @@ namespace JT808.Gateway.Abstractions | |||||
/// <param name="data"></param> | /// <param name="data"></param> | ||||
public static async void SendAsync(this IJT808Session session,byte[] data) | public static async void SendAsync(this IJT808Session session,byte[] data) | ||||
{ | { | ||||
if (data == null) return; | |||||
if (session.TransportProtocolType == JT808TransportProtocolType.tcp) | |||||
try | |||||
{ | { | ||||
if (session.Client.Connected) | |||||
await session.Client.SendAsync(data, SocketFlags.None); | |||||
if (data == null) return; | |||||
if (session.TransportProtocolType == JT808TransportProtocolType.tcp) | |||||
{ | |||||
if (session.Client.Connected) | |||||
await session.Client.SendAsync(data, SocketFlags.None); | |||||
} | |||||
else | |||||
{ | |||||
await session.Client.SendToAsync(data, SocketFlags.None, session.RemoteEndPoint); | |||||
} | |||||
} | } | ||||
else | |||||
catch (AggregateException ex) | |||||
{ | { | ||||
await session.Client.SendToAsync(data, SocketFlags.None, session.RemoteEndPoint); | |||||
} | |||||
catch (Exception) | |||||
{ | |||||
} | } | ||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// 下发消息 | /// 下发消息 | ||||
/// </summary> | /// </summary> | ||||
@@ -37,15 +49,26 @@ namespace JT808.Gateway.Abstractions | |||||
/// <param name="data"></param> | /// <param name="data"></param> | ||||
public static void Send(this IJT808Session session, byte[] data) | public static void Send(this IJT808Session session, byte[] data) | ||||
{ | { | ||||
if (data == null) return; | |||||
if (session.TransportProtocolType == JT808TransportProtocolType.tcp) | |||||
try | |||||
{ | { | ||||
if (session.Client.Connected) | |||||
session.Client.Send(data, SocketFlags.None); | |||||
if (data == null) return; | |||||
if (session.TransportProtocolType == JT808TransportProtocolType.tcp) | |||||
{ | |||||
if (session.Client.Connected) | |||||
session.Client.Send(data, SocketFlags.None); | |||||
} | |||||
else | |||||
{ | |||||
session.Client.SendTo(data, SocketFlags.None, session.RemoteEndPoint); | |||||
} | |||||
} | } | ||||
else | |||||
catch (AggregateException ex) | |||||
{ | { | ||||
session.Client.SendTo(data, SocketFlags.None, session.RemoteEndPoint); | |||||
} | |||||
catch (Exception) | |||||
{ | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -25,7 +25,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="JT808" Version="2.4.5" /> | <PackageReference Include="JT808" Version="2.4.5" /> | ||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" /> | <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" /> | ||||
<PackageReference Include="System.IO.Pipelines" Version="6.0.0" /> | |||||
<PackageReference Include="System.IO.Pipelines" Version="6.0.1" /> | |||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" /> | <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" /> | ||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" /> | <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
@@ -27,7 +27,7 @@ | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="System.IO.Pipelines" Version="6.0.0" /> | |||||
<PackageReference Include="System.IO.Pipelines" Version="6.0.1" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -64,7 +64,7 @@ namespace JT808.Gateway | |||||
Logger.LogWarning(ex, $"{ex.Message}:使用cmd命令[netsh http add urlacl url=http://*:{Configuration.WebApiPort}/ user=Everyone]"); | Logger.LogWarning(ex, $"{ex.Message}:使用cmd命令[netsh http add urlacl url=http://*:{Configuration.WebApiPort}/ user=Everyone]"); | ||||
} | } | ||||
Logger.LogInformation($"JT808 Http Server start at {IPAddress.Any}:{Configuration.WebApiPort}."); | Logger.LogInformation($"JT808 Http Server start at {IPAddress.Any}:{Configuration.WebApiPort}."); | ||||
Task.Run(async () => | |||||
Task.Factory.StartNew(async () => | |||||
{ | { | ||||
while (listener.IsListening) | while (listener.IsListening) | ||||
{ | { | ||||
@@ -95,7 +95,7 @@ namespace JT808.Gateway | |||||
public Task StartAsync(CancellationToken cancellationToken) | public Task StartAsync(CancellationToken cancellationToken) | ||||
{ | { | ||||
Logger.LogInformation($"JT808 TCP Server start at {IPAddress.Any}:{ConfigurationMonitor.CurrentValue.TcpPort}."); | Logger.LogInformation($"JT808 TCP Server start at {IPAddress.Any}:{ConfigurationMonitor.CurrentValue.TcpPort}."); | ||||
Task.Run(async () => | |||||
Task.Factory.StartNew(async () => | |||||
{ | { | ||||
while (!cancellationToken.IsCancellationRequested) | while (!cancellationToken.IsCancellationRequested) | ||||
{ | { | ||||
@@ -62,7 +62,7 @@ namespace JT808.Gateway | |||||
public Task StartAsync(CancellationToken cancellationToken) | public Task StartAsync(CancellationToken cancellationToken) | ||||
{ | { | ||||
Logger.LogInformation($"JT808 Udp Server start at {IPAddress.Any}:{ConfigurationMonitor.CurrentValue.UdpPort}."); | Logger.LogInformation($"JT808 Udp Server start at {IPAddress.Any}:{ConfigurationMonitor.CurrentValue.UdpPort}."); | ||||
Task.Run(async() => { | |||||
Task.Factory.StartNew(async() => { | |||||
while (!cancellationToken.IsCancellationRequested) | while (!cancellationToken.IsCancellationRequested) | ||||
{ | { | ||||
var buffer = ArrayPool<byte>.Shared.Rent(ConfigurationMonitor.CurrentValue.MiniNumBufferSize); | var buffer = ArrayPool<byte>.Shared.Rent(ConfigurationMonitor.CurrentValue.MiniNumBufferSize); | ||||
@@ -1,6 +1,6 @@ | |||||
<Project> | <Project> | ||||
<PropertyGroup> | <PropertyGroup> | ||||
<JT808DotNettyPackageVersion>2.3.6</JT808DotNettyPackageVersion> | <JT808DotNettyPackageVersion>2.3.6</JT808DotNettyPackageVersion> | ||||
<JT808GatewayPackageVersion>1.1.5</JT808GatewayPackageVersion> | |||||
<JT808GatewayPackageVersion>1.1.6</JT808GatewayPackageVersion> | |||||
</PropertyGroup> | </PropertyGroup> | ||||
</Project> | </Project> |