From 763b0d72ab6e0cae4faba7425d119726d21f7135 Mon Sep 17 00:00:00 2001 From: "SmallChi(Koike)" <564952747@qq.com> Date: Thu, 27 Jan 2022 22:01:25 +0800 Subject: [PATCH] =?UTF-8?q?v1.1.6=201.=E4=BF=AE=E5=A4=8Dwebapi=E8=B7=A8?= =?UTF-8?q?=E5=9F=9F=E9=97=AE=E9=A2=98=202.=E4=BF=AE=E5=A4=8D=E4=B8=8B?= =?UTF-8?q?=E5=8F=91=E6=97=B6socket=E5=BC=82=E5=B8=B8=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/JT808SessionExtensions.cs | 47 ++++++++++++++----- .../JT808.Gateway.Client.csproj | 2 +- src/JT808.Gateway/JT808.Gateway.csproj | 2 +- src/JT808.Gateway/JT808HttpServer.cs | 2 +- src/JT808.Gateway/JT808TcpServer.cs | 2 +- src/JT808.Gateway/JT808UdpServer.cs | 2 +- src/Version.props | 2 +- 7 files changed, 41 insertions(+), 18 deletions(-) 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