diff --git a/src/JT808.Gateway.Abstractions/Extensions/JT808SessionExtensions.cs b/src/JT808.Gateway.Abstractions/Extensions/JT808SessionExtensions.cs index f3e5ec4..4b64d50 100644 --- a/src/JT808.Gateway.Abstractions/Extensions/JT808SessionExtensions.cs +++ b/src/JT808.Gateway.Abstractions/Extensions/JT808SessionExtensions.cs @@ -19,17 +19,29 @@ namespace JT808.Gateway.Abstractions /// 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) + { + } } + /// /// 下发消息 /// @@ -37,15 +49,26 @@ namespace JT808.Gateway.Abstractions /// 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) + { + } } } diff --git a/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj b/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj index 0831ad7..41d2262 100644 --- a/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj +++ b/src/JT808.Gateway.Client/JT808.Gateway.Client.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/JT808.Gateway/JT808.Gateway.csproj b/src/JT808.Gateway/JT808.Gateway.csproj index 203e679..719813f 100644 --- a/src/JT808.Gateway/JT808.Gateway.csproj +++ b/src/JT808.Gateway/JT808.Gateway.csproj @@ -27,7 +27,7 @@ - + diff --git a/src/JT808.Gateway/JT808HttpServer.cs b/src/JT808.Gateway/JT808HttpServer.cs index f09be38..ab3a826 100644 --- a/src/JT808.Gateway/JT808HttpServer.cs +++ b/src/JT808.Gateway/JT808HttpServer.cs @@ -64,7 +64,7 @@ namespace JT808.Gateway 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}."); - Task.Run(async () => + Task.Factory.StartNew(async () => { while (listener.IsListening) { diff --git a/src/JT808.Gateway/JT808TcpServer.cs b/src/JT808.Gateway/JT808TcpServer.cs index 4f730ce..93972e4 100644 --- a/src/JT808.Gateway/JT808TcpServer.cs +++ b/src/JT808.Gateway/JT808TcpServer.cs @@ -95,7 +95,7 @@ namespace JT808.Gateway public Task StartAsync(CancellationToken cancellationToken) { Logger.LogInformation($"JT808 TCP Server start at {IPAddress.Any}:{ConfigurationMonitor.CurrentValue.TcpPort}."); - Task.Run(async () => + Task.Factory.StartNew(async () => { while (!cancellationToken.IsCancellationRequested) { diff --git a/src/JT808.Gateway/JT808UdpServer.cs b/src/JT808.Gateway/JT808UdpServer.cs index 62d4f5d..2112417 100644 --- a/src/JT808.Gateway/JT808UdpServer.cs +++ b/src/JT808.Gateway/JT808UdpServer.cs @@ -62,7 +62,7 @@ namespace JT808.Gateway public Task StartAsync(CancellationToken cancellationToken) { Logger.LogInformation($"JT808 Udp Server start at {IPAddress.Any}:{ConfigurationMonitor.CurrentValue.UdpPort}."); - Task.Run(async() => { + Task.Factory.StartNew(async() => { while (!cancellationToken.IsCancellationRequested) { var buffer = ArrayPool.Shared.Rent(ConfigurationMonitor.CurrentValue.MiniNumBufferSize); diff --git a/src/Version.props b/src/Version.props index 027d647..86d4191 100644 --- a/src/Version.props +++ b/src/Version.props @@ -1,6 +1,6 @@  2.3.6 - 1.1.5 + 1.1.6 \ No newline at end of file