From cd5c29548483028bd6677abaf1a4af6e4eeacf04 Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Wed, 5 Jul 2017 21:57:37 +0200 Subject: [PATCH 01/18] Adding .NET Standard 1.3 support --- .../MQTTnet.Netstandard.csproj | 26 +++++++++++++++++++ MQTTnet.nuspec | 16 ++++++++++-- MQTTnet.sln | 23 ++++++++++++++-- README.md | 6 ++--- 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj diff --git a/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj new file mode 100644 index 0000000..a4a82a7 --- /dev/null +++ b/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj @@ -0,0 +1,26 @@ + + + + netstandard1.3 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MQTTnet.nuspec b/MQTTnet.nuspec index ab1869b..bc4cb34 100644 --- a/MQTTnet.nuspec +++ b/MQTTnet.nuspec @@ -15,9 +15,17 @@ * [Server] Added TLS 1.2 support (but not for UWP) (thanks to Zazzmatazz) * [Client] Added TLS 1.2 support (thanks to Zazzmatazz) * [Core] Optimized async task management -* [Nuget] Fixed x64 files +* [Nuget] Fixed x64 files +* [.NET Standard] Added support for .NET Standard 1.3 Copyright Christian Kratky 2016-2017 - MQTT MQTTClient MQTTServer MQTTBroker Broker + MQTT MQTTClient MQTTServer MQTTBroker Broker + + + + + + + @@ -51,6 +59,10 @@ + + + + \ No newline at end of file diff --git a/MQTTnet.sln b/MQTTnet.sln index 8b8d283..5031511 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26430.12 +VisualStudioVersion = 15.0.26430.14 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.Core.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Core.Tests.csproj", "{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}" EndProject @@ -13,7 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9248C2E1 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frameworks", "Frameworks", "{32A630A7-2598-41D7-B625-204CD906F5FB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.Core", "MQTTnet.Core\MQTTnet.Core.csproj", "{2ECB99E4-72D0-4C23-99BA-93D511D3967D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core", "MQTTnet.Core\MQTTnet.Core.csproj", "{2ECB99E4-72D0-4C23-99BA-93D511D3967D}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{002203AF-2565-4C0D-95ED-027FDEFE0C35}" ProjectSection(SolutionItems) = preProject @@ -26,6 +26,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.NetFramewor EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.UniversalWindows", "Tests\MQTTnet.TestApp.UniversalWindows\MQTTnet.TestApp.UniversalWindows.csproj", "{FF1F72D6-9524-4422-9497-3CC0002216ED}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.Netstandard", "Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj", "{3587E506-55A2-4EB3-99C7-DC01E42D25D2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -152,6 +154,22 @@ Global {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|x86.ActiveCfg = Release|x86 {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|x86.Build.0 = Release|x86 {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|x86.Deploy.0 = Release|x86 + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|ARM.ActiveCfg = Debug|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|ARM.Build.0 = Debug|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x64.ActiveCfg = Debug|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x64.Build.0 = Debug|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x86.ActiveCfg = Debug|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x86.Build.0 = Debug|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|Any CPU.Build.0 = Release|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|ARM.ActiveCfg = Release|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|ARM.Build.0 = Release|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|x64.ActiveCfg = Release|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|x64.Build.0 = Release|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|x86.ActiveCfg = Release|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -163,5 +181,6 @@ Global {1A1B7F51-5328-4395-9D9C-07D70965825E} = {32A630A7-2598-41D7-B625-204CD906F5FB} {D9D74F33-6943-49B2-B765-7BD589082098} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} {FF1F72D6-9524-4422-9497-3CC0002216ED} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} + {3587E506-55A2-4EB3-99C7-DC01E42D25D2} = {32A630A7-2598-41D7-B625-204CD906F5FB} EndGlobalSection EndGlobal diff --git a/README.md b/README.md index 777e535..faeb120 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ MQTTnet is a .NET library for MQTT based communication. It provides a MQTT clien * Lightweight (only the low level implementation of MQTT, no overhead) ## Supported frameworks -* .NET Standard 1.1+ +* .NET Standard 1.3+ * .NET Core 1.1+ * .NET Core App 1.1+ * .NET Framework 4.5.2+ (x86, x64, AnyCPU) @@ -45,7 +45,7 @@ If you use this library and want to see your project here please let me know. # MqttClient ## Example -```c# +```csharp var options = new MqttClientOptions { Server = "localhost" @@ -119,7 +119,7 @@ while (true) ## Example -```c# +```csharp var options = new MqttServerOptions { ConnectionValidator = p => From eeb324257350930f210c9e09d1c838450fab4caa Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Thu, 6 Jul 2017 00:27:19 +0200 Subject: [PATCH 02/18] Fixed Assembly name --- Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj index a4a82a7..3ac6e54 100644 --- a/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj @@ -2,6 +2,8 @@ netstandard1.3 + MQTTnet + MQTTnet From 35344b27c57517902277cf8be3df4d14cd8c05af Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Mon, 10 Jul 2017 21:19:06 +0200 Subject: [PATCH 03/18] Fixed build settings --- .../MQTTnet.Netstandard/MQTTnet.Netstandard.csproj | 4 ++++ Frameworks/MQTTnet.UniversalWindows/project.json | 1 - MQTTnet.nuspec | 10 ++-------- MQTTnet.sln | 12 +++++++----- Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs | 5 +++++ 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj index 3ac6e54..f5875bb 100644 --- a/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj @@ -6,6 +6,10 @@ MQTTnet + + + + diff --git a/Frameworks/MQTTnet.UniversalWindows/project.json b/Frameworks/MQTTnet.UniversalWindows/project.json index 239b57e..92d1456 100644 --- a/Frameworks/MQTTnet.UniversalWindows/project.json +++ b/Frameworks/MQTTnet.UniversalWindows/project.json @@ -6,7 +6,6 @@ "uap10.0": {} }, "runtimes": { - "win10": {}, "win10-arm": {}, "win10-arm-aot": {}, "win10-x86": {}, diff --git a/MQTTnet.nuspec b/MQTTnet.nuspec index bc4cb34..0a40cc6 100644 --- a/MQTTnet.nuspec +++ b/MQTTnet.nuspec @@ -2,7 +2,7 @@ MQTTnet - 2.1.3.0 + 2.1.4.0 Christian Kratky Christian Kratky https://github.com/chkr1011/MQTTnet/blob/master/LICENSE @@ -10,13 +10,7 @@ https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png false MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). - * [Core] Any exception while accessing the underlying data source is now rethrown as "MqttCommunicationException". -* [Core] Extended exception information when an invalid packet type is received. -* [Server] Added TLS 1.2 support (but not for UWP) (thanks to Zazzmatazz) -* [Client] Added TLS 1.2 support (thanks to Zazzmatazz) -* [Core] Optimized async task management -* [Nuget] Fixed x64 files -* [.NET Standard] Added support for .NET Standard 1.3 + * [.NET Standard] Added support for .NET Standard 1.3 (Thanks to 1iveowl) Copyright Christian Kratky 2016-2017 MQTT MQTTClient MQTTServer MQTTBroker Broker diff --git a/MQTTnet.sln b/MQTTnet.sln index 5031511..dabb915 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -26,7 +26,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.NetFramewor EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.UniversalWindows", "Tests\MQTTnet.TestApp.UniversalWindows\MQTTnet.TestApp.UniversalWindows.csproj", "{FF1F72D6-9524-4422-9497-3CC0002216ED}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.Netstandard", "Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj", "{3587E506-55A2-4EB3-99C7-DC01E42D25D2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Netstandard", "Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj", "{3587E506-55A2-4EB3-99C7-DC01E42D25D2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -73,6 +73,7 @@ Global {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Release|x86.ActiveCfg = Release|x86 {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Release|x86.Build.0 = Release|x86 {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|Any CPU.Build.0 = Debug|Any CPU {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|ARM.ActiveCfg = Debug|ARM {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|ARM.Build.0 = Debug|ARM {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|x64.ActiveCfg = Debug|x64 @@ -135,6 +136,7 @@ Global {D9D74F33-6943-49B2-B765-7BD589082098}.Release|x86.ActiveCfg = Release|x86 {D9D74F33-6943-49B2-B765-7BD589082098}.Release|x86.Build.0 = Release|x86 {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|Any CPU.Build.0 = Debug|Any CPU {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|ARM.ActiveCfg = Debug|ARM {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|ARM.Build.0 = Debug|ARM {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|ARM.Deploy.0 = Debug|ARM @@ -158,10 +160,10 @@ Global {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|Any CPU.Build.0 = Debug|Any CPU {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|ARM.ActiveCfg = Debug|Any CPU {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|ARM.Build.0 = Debug|Any CPU - {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x64.ActiveCfg = Debug|Any CPU - {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x64.Build.0 = Debug|Any CPU - {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x86.ActiveCfg = Debug|Any CPU - {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x86.Build.0 = Debug|Any CPU + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x64.ActiveCfg = Debug|x64 + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x64.Build.0 = Debug|x64 + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x86.ActiveCfg = Debug|x86 + {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Debug|x86.Build.0 = Debug|x86 {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|Any CPU.ActiveCfg = Release|Any CPU {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|Any CPU.Build.0 = Release|Any CPU {3587E506-55A2-4EB3-99C7-DC01E42D25D2}.Release|ARM.ActiveCfg = Release|Any CPU diff --git a/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs b/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs index b1dcf6b..634d5b4 100644 --- a/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs +++ b/Tests/MQTTnet.Core.Tests/TestMqttServerAdapter.cs @@ -8,6 +8,11 @@ namespace MQTTnet.Core.Tests { public event EventHandler ClientConnected; + public void FireClientConnectedEvent(MqttClientConnectedEventArgs eventArgs) + { + ClientConnected?.Invoke(this, eventArgs); + } + public void Start(MqttServerOptions options) { } From d0e8a0c4e53febf4960828beb045976de5f5e68e Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Wed, 12 Jul 2017 19:56:57 +0200 Subject: [PATCH 04/18] Refactor .NET Standard projects --- .../MQTTnet.NetCoreApp/MQTTnet.NetCoreApp.csproj | 11 +++++++++++ .../Implementations/MqttServerAdapter.cs | 0 .../Implementations/MqttTcpChannel.cs | 0 .../MqttClientFactory.cs | 0 .../MqttServerFactory.cs | 0 .../MQTTnet.Netstandard/MQTTnet.Netstandard.csproj | 11 ----------- MQTTnet.sln | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) rename Frameworks/{MQTTnet.NetCoreApp => MQTTnet.NetStandard}/Implementations/MqttServerAdapter.cs (100%) rename Frameworks/{MQTTnet.NetCoreApp => MQTTnet.NetStandard}/Implementations/MqttTcpChannel.cs (100%) rename Frameworks/{MQTTnet.NetCoreApp => MQTTnet.NetStandard}/MqttClientFactory.cs (100%) rename Frameworks/{MQTTnet.NetCoreApp => MQTTnet.NetStandard}/MqttServerFactory.cs (100%) diff --git a/Frameworks/MQTTnet.NetCoreApp/MQTTnet.NetCoreApp.csproj b/Frameworks/MQTTnet.NetCoreApp/MQTTnet.NetCoreApp.csproj index ec45201..5bc9e6d 100644 --- a/Frameworks/MQTTnet.NetCoreApp/MQTTnet.NetCoreApp.csproj +++ b/Frameworks/MQTTnet.NetCoreApp/MQTTnet.NetCoreApp.csproj @@ -27,8 +27,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetCoreApp/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs similarity index 100% rename from Frameworks/MQTTnet.NetCoreApp/Implementations/MqttServerAdapter.cs rename to Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs diff --git a/Frameworks/MQTTnet.NetCoreApp/Implementations/MqttTcpChannel.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs similarity index 100% rename from Frameworks/MQTTnet.NetCoreApp/Implementations/MqttTcpChannel.cs rename to Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs diff --git a/Frameworks/MQTTnet.NetCoreApp/MqttClientFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs similarity index 100% rename from Frameworks/MQTTnet.NetCoreApp/MqttClientFactory.cs rename to Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs diff --git a/Frameworks/MQTTnet.NetCoreApp/MqttServerFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs similarity index 100% rename from Frameworks/MQTTnet.NetCoreApp/MqttServerFactory.cs rename to Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs diff --git a/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj index f5875bb..10ffeed 100644 --- a/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj @@ -10,21 +10,10 @@ - - - - - - - - - - - diff --git a/MQTTnet.sln b/MQTTnet.sln index dabb915..58e427e 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26430.14 +VisualStudioVersion = 15.0.26430.15 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.Core.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Core.Tests.csproj", "{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}" EndProject @@ -26,7 +26,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.NetFramewor EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.UniversalWindows", "Tests\MQTTnet.TestApp.UniversalWindows\MQTTnet.TestApp.UniversalWindows.csproj", "{FF1F72D6-9524-4422-9497-3CC0002216ED}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Netstandard", "Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj", "{3587E506-55A2-4EB3-99C7-DC01E42D25D2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.NetStandard", "Frameworks\MQTTnet.Netstandard\MQTTnet.NetStandard.csproj", "{3587E506-55A2-4EB3-99C7-DC01E42D25D2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From d26d29e9a62b43d5704bffa63520866643ece2fa Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Thu, 13 Jul 2017 15:00:35 +0200 Subject: [PATCH 05/18] PowerShell build --- Build/build.ps1 | 14 +++++ .../MQTTnet.NetCoreApp.csproj | 45 -------------- .../MQTTnet.UniversalWindows.csproj | 2 +- .../MQTTnet.UniversalWindows/project.json | 2 +- MQTTnet.nuspec | 62 ------------------- MQTTnet.sln | 24 ++----- .../MQTTnet.TestApp.UniversalWindows.csproj | 8 +-- 7 files changed, 24 insertions(+), 133 deletions(-) create mode 100644 Build/build.ps1 delete mode 100644 Frameworks/MQTTnet.NetCoreApp/MQTTnet.NetCoreApp.csproj delete mode 100644 MQTTnet.nuspec diff --git a/Build/build.ps1 b/Build/build.ps1 new file mode 100644 index 0000000..322a2c8 --- /dev/null +++ b/Build/build.ps1 @@ -0,0 +1,14 @@ +param([string]$version) + +if ([string]::IsNullOrEmpty($version)) {$version = "0.0.1"} + +$msbuild = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" +&$msbuild ..\Frameworks\MQTTnet.NetFramework\MQTTnet.NetFramework.csproj /t:Build /p:Configuration="Release" +&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" +&$msbuild ..\Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj /t:Build /p:Configuration="Release" + + + +Remove-Item .\NuGet -Force -Recurse +New-Item -ItemType Directory -Force -Path .\NuGet +NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetCoreApp/MQTTnet.NetCoreApp.csproj b/Frameworks/MQTTnet.NetCoreApp/MQTTnet.NetCoreApp.csproj deleted file mode 100644 index 5bc9e6d..0000000 --- a/Frameworks/MQTTnet.NetCoreApp/MQTTnet.NetCoreApp.csproj +++ /dev/null @@ -1,45 +0,0 @@ - - - - netcoreapp1.1 - Christian Kratky - Christian Kratky - MQTTnet - MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). - Copyright © Christian Kratky 2016-2017 - 2.1.1.0 - 2.1.1.0 - 2.1.1.0 - False - MQTTnet - MQTTnet - MQTTnet.NetCore - https://github.com/chkr1011/MQTTnet - https://github.com/chkr1011/MQTTnet - MQTT MQTTClient MQTTServer MQTTBroker Broker - https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png - https://github.com/chkr1011/MQTTnet/blob/master/LICENSE - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj b/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj index fa6f897..ad3382c 100644 --- a/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj +++ b/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj @@ -11,7 +11,7 @@ MQTTnet en-US UAP - 10.0.14393.0 + 10.0.10586.0 10.0.10240.0 14 512 diff --git a/Frameworks/MQTTnet.UniversalWindows/project.json b/Frameworks/MQTTnet.UniversalWindows/project.json index 92d1456..693e373 100644 --- a/Frameworks/MQTTnet.UniversalWindows/project.json +++ b/Frameworks/MQTTnet.UniversalWindows/project.json @@ -1,6 +1,6 @@ { "dependencies": { - "Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0" + "Microsoft.NETCore.UniversalWindowsPlatform": "5.3.3" }, "frameworks": { "uap10.0": {} diff --git a/MQTTnet.nuspec b/MQTTnet.nuspec deleted file mode 100644 index 0a40cc6..0000000 --- a/MQTTnet.nuspec +++ /dev/null @@ -1,62 +0,0 @@ - - - - MQTTnet - 2.1.4.0 - Christian Kratky - Christian Kratky - https://github.com/chkr1011/MQTTnet/blob/master/LICENSE - https://github.com/chkr1011/MQTTnet - https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png - false - MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). - * [.NET Standard] Added support for .NET Standard 1.3 (Thanks to 1iveowl) - Copyright Christian Kratky 2016-2017 - MQTT MQTTClient MQTTServer MQTTBroker Broker - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MQTTnet.sln b/MQTTnet.sln index 58e427e..f6a4ad0 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -17,11 +17,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core", "MQTTnet.Cor EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{002203AF-2565-4C0D-95ED-027FDEFE0C35}" ProjectSection(SolutionItems) = preProject - MQTTnet.nuspec = MQTTnet.nuspec + Build\build.ps1 = Build\build.ps1 + Build\MQTTnet.nuspec = Build\MQTTnet.nuspec EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.NetCoreApp", "Frameworks\MQTTnet.NetCoreApp\MQTTnet.NetCoreApp.csproj", "{1A1B7F51-5328-4395-9D9C-07D70965825E}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.NetFramework", "Tests\MQTTnet.TestApp.NetFramework\MQTTnet.TestApp.NetFramework.csproj", "{D9D74F33-6943-49B2-B765-7BD589082098}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.UniversalWindows", "Tests\MQTTnet.TestApp.UniversalWindows\MQTTnet.TestApp.UniversalWindows.csproj", "{FF1F72D6-9524-4422-9497-3CC0002216ED}" @@ -81,6 +80,7 @@ Global {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|x86.ActiveCfg = Debug|x86 {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|x86.Build.0 = Debug|x86 {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|Any CPU.Build.0 = Release|Any CPU {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|ARM.ActiveCfg = Release|ARM {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|ARM.Build.0 = Release|ARM {BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|x64.ActiveCfg = Release|x64 @@ -103,22 +103,6 @@ Global {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x64.Build.0 = Release|x64 {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x86.ActiveCfg = Release|x86 {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x86.Build.0 = Release|x86 - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Debug|ARM.ActiveCfg = Debug|Any CPU - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Debug|ARM.Build.0 = Debug|Any CPU - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Debug|x64.ActiveCfg = Debug|x64 - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Debug|x64.Build.0 = Debug|x64 - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Debug|x86.ActiveCfg = Debug|x86 - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Debug|x86.Build.0 = Debug|x86 - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Release|Any CPU.Build.0 = Release|Any CPU - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Release|ARM.ActiveCfg = Release|Any CPU - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Release|ARM.Build.0 = Release|Any CPU - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Release|x64.ActiveCfg = Release|x64 - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Release|x64.Build.0 = Release|x64 - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Release|x86.ActiveCfg = Release|x86 - {1A1B7F51-5328-4395-9D9C-07D70965825E}.Release|x86.Build.0 = Release|x86 {D9D74F33-6943-49B2-B765-7BD589082098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D9D74F33-6943-49B2-B765-7BD589082098}.Debug|Any CPU.Build.0 = Debug|Any CPU {D9D74F33-6943-49B2-B765-7BD589082098}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -147,6 +131,7 @@ Global {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|x86.Build.0 = Debug|x86 {FF1F72D6-9524-4422-9497-3CC0002216ED}.Debug|x86.Deploy.0 = Debug|x86 {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|Any CPU.Build.0 = Release|Any CPU {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|ARM.ActiveCfg = Release|ARM {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|ARM.Build.0 = Release|ARM {FF1F72D6-9524-4422-9497-3CC0002216ED}.Release|ARM.Deploy.0 = Release|ARM @@ -180,7 +165,6 @@ Global {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D} = {32A630A7-2598-41D7-B625-204CD906F5FB} {BD60C727-D8E8-40C3-B8E3-C95A864AE611} = {32A630A7-2598-41D7-B625-204CD906F5FB} - {1A1B7F51-5328-4395-9D9C-07D70965825E} = {32A630A7-2598-41D7-B625-204CD906F5FB} {D9D74F33-6943-49B2-B765-7BD589082098} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} {FF1F72D6-9524-4422-9497-3CC0002216ED} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} {3587E506-55A2-4EB3-99C7-DC01E42D25D2} = {32A630A7-2598-41D7-B625-204CD906F5FB} diff --git a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj b/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj index 383fd8e..502c3be 100644 --- a/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj +++ b/Tests/MQTTnet.TestApp.UniversalWindows/MQTTnet.TestApp.UniversalWindows.csproj @@ -11,8 +11,8 @@ MQTTnet.TestApp.UniversalWindows en-US UAP - 10.0.14393.0 - 10.0.10240.0 + 10.0.15063.0 + 10.0.15063.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} @@ -137,7 +137,7 @@ - 5.2.3 + 5.3.3 @@ -150,7 +150,7 @@ ;2008 true full - AnyCPU + x86 false prompt MinimumRecommendedRules.ruleset From 83f6ae4e5480510b9da549fbde9acb595918ed10 Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Thu, 13 Jul 2017 15:01:35 +0200 Subject: [PATCH 06/18] UWP target update --- .../MQTTnet.UniversalWindows.csproj | 12 +++++++----- Frameworks/MQTTnet.UniversalWindows/project.json | 16 ---------------- 2 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 Frameworks/MQTTnet.UniversalWindows/project.json diff --git a/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj b/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj index ad3382c..791ee28 100644 --- a/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj +++ b/Frameworks/MQTTnet.UniversalWindows/MQTTnet.UniversalWindows.csproj @@ -11,11 +11,12 @@ MQTTnet en-US UAP - 10.0.10586.0 + 10.0.15063.0 10.0.10240.0 14 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot AnyCPU @@ -108,10 +109,6 @@ false bin\x64\Release\MQTTnet.XML - - - - @@ -126,6 +123,11 @@ MQTTnet.Core + + + 5.3.3 + + 14.0 diff --git a/Frameworks/MQTTnet.UniversalWindows/project.json b/Frameworks/MQTTnet.UniversalWindows/project.json deleted file mode 100644 index 693e373..0000000 --- a/Frameworks/MQTTnet.UniversalWindows/project.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "dependencies": { - "Microsoft.NETCore.UniversalWindowsPlatform": "5.3.3" - }, - "frameworks": { - "uap10.0": {} - }, - "runtimes": { - "win10-arm": {}, - "win10-arm-aot": {}, - "win10-x86": {}, - "win10-x86-aot": {}, - "win10-x64": {}, - "win10-x64-aot": {} - } -} \ No newline at end of file From 98d7bc980c54c03d2cc6f39805e63e9508c22892 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Thu, 13 Jul 2017 20:28:49 +0200 Subject: [PATCH 07/18] Add an event to receive all application messages at server level. --- ...MqttApplicationMessageReceivedEventArgs.cs | 2 +- MQTTnet.Core/Client/MqttClient.cs | 8 +-- .../MqttApplicationMessageExtensions.cs | 10 +++ ...MqttApplicationMessageReceivedEventArgs.cs | 17 +++++ MQTTnet.Core/Server/MqttClientSession.cs | 7 ++- .../Server/MqttClientSessionsManager.cs | 8 ++- MQTTnet.Core/Server/MqttServer.cs | 3 + MQTTnet.nuspec | 63 +++++++++++++++++++ MQTTnet.sln | 4 +- Build/build.ps1 => build.ps1 | 2 +- 10 files changed, 110 insertions(+), 14 deletions(-) rename MQTTnet.Core/{ => Client}/MqttApplicationMessageReceivedEventArgs.cs (93%) create mode 100644 MQTTnet.Core/Server/MqttApplicationMessageReceivedEventArgs.cs create mode 100644 MQTTnet.nuspec rename Build/build.ps1 => build.ps1 (86%) diff --git a/MQTTnet.Core/MqttApplicationMessageReceivedEventArgs.cs b/MQTTnet.Core/Client/MqttApplicationMessageReceivedEventArgs.cs similarity index 93% rename from MQTTnet.Core/MqttApplicationMessageReceivedEventArgs.cs rename to MQTTnet.Core/Client/MqttApplicationMessageReceivedEventArgs.cs index c624bea..9e12028 100644 --- a/MQTTnet.Core/MqttApplicationMessageReceivedEventArgs.cs +++ b/MQTTnet.Core/Client/MqttApplicationMessageReceivedEventArgs.cs @@ -1,6 +1,6 @@ using System; -namespace MQTTnet.Core +namespace MQTTnet.Core.Client { public sealed class MqttApplicationMessageReceivedEventArgs : EventArgs { diff --git a/MQTTnet.Core/Client/MqttClient.cs b/MQTTnet.Core/Client/MqttClient.cs index cc3ebee..ebf2cfd 100644 --- a/MQTTnet.Core/Client/MqttClient.cs +++ b/MQTTnet.Core/Client/MqttClient.cs @@ -234,13 +234,7 @@ namespace MQTTnet.Core.Client _processedPublishPackets.Add(publishPacket.PacketIdentifier); } - var applicationMessage = new MqttApplicationMessage( - publishPacket.Topic, - publishPacket.Payload, - publishPacket.QualityOfServiceLevel, - publishPacket.Retain - ); - + var applicationMessage = publishPacket.ToApplicationMessage(); ApplicationMessageReceived?.Invoke(this, new MqttApplicationMessageReceivedEventArgs(applicationMessage)); } diff --git a/MQTTnet.Core/Internal/MqttApplicationMessageExtensions.cs b/MQTTnet.Core/Internal/MqttApplicationMessageExtensions.cs index 71cdb7f..7d3c665 100644 --- a/MQTTnet.Core/Internal/MqttApplicationMessageExtensions.cs +++ b/MQTTnet.Core/Internal/MqttApplicationMessageExtensions.cs @@ -4,6 +4,16 @@ namespace MQTTnet.Core.Internal { internal static class MqttApplicationMessageExtensions { + public static MqttApplicationMessage ToApplicationMessage(this MqttPublishPacket publishPacket) + { + return new MqttApplicationMessage( + publishPacket.Topic, + publishPacket.Payload, + publishPacket.QualityOfServiceLevel, + publishPacket.Retain + ); + } + public static MqttPublishPacket ToPublishPacket(this MqttApplicationMessage applicationMessage) { if (applicationMessage == null) diff --git a/MQTTnet.Core/Server/MqttApplicationMessageReceivedEventArgs.cs b/MQTTnet.Core/Server/MqttApplicationMessageReceivedEventArgs.cs new file mode 100644 index 0000000..4f2cc80 --- /dev/null +++ b/MQTTnet.Core/Server/MqttApplicationMessageReceivedEventArgs.cs @@ -0,0 +1,17 @@ +using System; + +namespace MQTTnet.Core.Server +{ + public sealed class MqttApplicationMessageReceivedEventArgs : EventArgs + { + public MqttApplicationMessageReceivedEventArgs(string clientId, MqttApplicationMessage applicationMessage) + { + ClientId = clientId; + ApplicationMessage = applicationMessage ?? throw new ArgumentNullException(nameof(applicationMessage)); + } + + public string ClientId { get; } + + public MqttApplicationMessage ApplicationMessage { get; } + } +} diff --git a/MQTTnet.Core/Server/MqttClientSession.cs b/MQTTnet.Core/Server/MqttClientSession.cs index 19b4cfd..b89e73e 100644 --- a/MQTTnet.Core/Server/MqttClientSession.cs +++ b/MQTTnet.Core/Server/MqttClientSession.cs @@ -19,20 +19,23 @@ namespace MQTTnet.Core.Server private readonly MqttClientMessageQueue _messageQueue; private readonly Action _publishPacketReceivedCallback; private readonly MqttServerOptions _options; - + private CancellationTokenSource _cancellationTokenSource; private IMqttCommunicationAdapter _adapter; private string _identifier; private MqttApplicationMessage _willApplicationMessage; - public MqttClientSession(MqttServerOptions options, Action publishPacketReceivedCallback) + public MqttClientSession(string clientId, MqttServerOptions options, Action publishPacketReceivedCallback) { + ClientId = clientId; _options = options ?? throw new ArgumentNullException(nameof(options)); _publishPacketReceivedCallback = publishPacketReceivedCallback ?? throw new ArgumentNullException(nameof(publishPacketReceivedCallback)); _messageQueue = new MqttClientMessageQueue(options); } + public string ClientId { get; } + public bool IsConnected => _adapter != null; public async Task RunAsync(string identifier, MqttApplicationMessage willApplicationMessage, IMqttCommunicationAdapter adapter) diff --git a/MQTTnet.Core/Server/MqttClientSessionsManager.cs b/MQTTnet.Core/Server/MqttClientSessionsManager.cs index 2a9a0b2..ae4d865 100644 --- a/MQTTnet.Core/Server/MqttClientSessionsManager.cs +++ b/MQTTnet.Core/Server/MqttClientSessionsManager.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using MQTTnet.Core.Adapter; using MQTTnet.Core.Diagnostics; using MQTTnet.Core.Exceptions; +using MQTTnet.Core.Internal; using MQTTnet.Core.Packets; using MQTTnet.Core.Protocol; @@ -21,6 +22,8 @@ namespace MQTTnet.Core.Server _options = options ?? throw new ArgumentNullException(nameof(options)); } + public event EventHandler ApplicationMessageReceived; + public async Task RunClientSessionAsync(MqttClientConnectedEventArgs eventArgs) { try @@ -114,7 +117,7 @@ namespace MQTTnet.Core.Server { isExistingSession = false; - clientSession = new MqttClientSession(_options, DispatchPublishPacket); + clientSession = new MqttClientSession(connectPacket.ClientId, _options, DispatchPublishPacket); _clientSessions[connectPacket.ClientId] = clientSession; MqttTrace.Verbose(nameof(MqttClientSessionsManager), $"Created a new session for client '{connectPacket.ClientId}'."); @@ -126,6 +129,9 @@ namespace MQTTnet.Core.Server private void DispatchPublishPacket(MqttClientSession senderClientSession, MqttPublishPacket publishPacket) { + var eventArgs = new MqttApplicationMessageReceivedEventArgs(senderClientSession.ClientId, publishPacket.ToApplicationMessage()); + ApplicationMessageReceived?.Invoke(this, eventArgs); + foreach (var clientSession in _clientSessions.Values.ToList()) { clientSession.EnqueuePublishPacket(senderClientSession, publishPacket); diff --git a/MQTTnet.Core/Server/MqttServer.cs b/MQTTnet.Core/Server/MqttServer.cs index e1cda96..f7f7932 100644 --- a/MQTTnet.Core/Server/MqttServer.cs +++ b/MQTTnet.Core/Server/MqttServer.cs @@ -21,6 +21,7 @@ namespace MQTTnet.Core.Server _adapters = adapters ?? throw new ArgumentNullException(nameof(adapters)); _clientSessionsManager = new MqttClientSessionsManager(options); + _clientSessionsManager.ApplicationMessageReceived += (s, e) => ApplicationMessageReceived?.Invoke(s, e); } public IList GetConnectedClients() @@ -30,6 +31,8 @@ namespace MQTTnet.Core.Server public event EventHandler ClientConnected; + public event EventHandler ApplicationMessageReceived; + public void InjectClient(string identifier, IMqttCommunicationAdapter adapter) { if (adapter == null) throw new ArgumentNullException(nameof(adapter)); diff --git a/MQTTnet.nuspec b/MQTTnet.nuspec new file mode 100644 index 0000000..28f8ee3 --- /dev/null +++ b/MQTTnet.nuspec @@ -0,0 +1,63 @@ + + + + MQTTnet + 2.1.4.0 + Christian Kratky + Christian Kratky + https://github.com/chkr1011/MQTTnet/blob/master/LICENSE + https://github.com/chkr1011/MQTTnet + https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png + false + MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). + * [.NET Standard] Added support for .NET Standard 1.3 (Thanks to 1iveowl) +* [Server] Added an event to receive every application message + Copyright Christian Kratky 2016-2017 + MQTT MQTTClient MQTTServer MQTTBroker Broker + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MQTTnet.sln b/MQTTnet.sln index f6a4ad0..17e73d0 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -17,8 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core", "MQTTnet.Cor EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{002203AF-2565-4C0D-95ED-027FDEFE0C35}" ProjectSection(SolutionItems) = preProject - Build\build.ps1 = Build\build.ps1 - Build\MQTTnet.nuspec = Build\MQTTnet.nuspec + build.ps1 = build.ps1 + MQTTnet.nuspec = MQTTnet.nuspec EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.NetFramework", "Tests\MQTTnet.TestApp.NetFramework\MQTTnet.TestApp.NetFramework.csproj", "{D9D74F33-6943-49B2-B765-7BD589082098}" diff --git a/Build/build.ps1 b/build.ps1 similarity index 86% rename from Build/build.ps1 rename to build.ps1 index 322a2c8..e30c896 100644 --- a/Build/build.ps1 +++ b/build.ps1 @@ -11,4 +11,4 @@ $msbuild = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBui Remove-Item .\NuGet -Force -Recurse New-Item -ItemType Directory -Force -Path .\NuGet -NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version \ No newline at end of file +.\NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version \ No newline at end of file From 39beb4912b85511c776384e1117e541219590648 Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Thu, 13 Jul 2017 20:32:58 +0200 Subject: [PATCH 08/18] Added missing Nuspec file Added missing Nuspec file --- Build/MQTTnet.nuspec | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Build/MQTTnet.nuspec diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec new file mode 100644 index 0000000..c418fba --- /dev/null +++ b/Build/MQTTnet.nuspec @@ -0,0 +1,44 @@ + + + + MQTTnet + 0 + Christian Kratky + Christian Kratky + https://github.com/chkr1011/MQTTnet/blob/master/LICENSE + https://github.com/chkr1011/MQTTnet + https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png + false + MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). + * [.NET Standard] Added support for .NET Standard 1.3 (Thanks to 1iveowl) + Copyright Christian Kratky 2016-2017 + MQTT MQTTClient MQTTServer MQTTBroker Broker + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From b2e3686f59c43760642b84c8230643d93d78047d Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Thu, 13 Jul 2017 23:13:56 +0200 Subject: [PATCH 09/18] Fix build files --- MQTTnet.nuspec | 63 -------------------------------------------------- build.ps1 | 14 ----------- 2 files changed, 77 deletions(-) delete mode 100644 MQTTnet.nuspec delete mode 100644 build.ps1 diff --git a/MQTTnet.nuspec b/MQTTnet.nuspec deleted file mode 100644 index 28f8ee3..0000000 --- a/MQTTnet.nuspec +++ /dev/null @@ -1,63 +0,0 @@ - - - - MQTTnet - 2.1.4.0 - Christian Kratky - Christian Kratky - https://github.com/chkr1011/MQTTnet/blob/master/LICENSE - https://github.com/chkr1011/MQTTnet - https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png - false - MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). - * [.NET Standard] Added support for .NET Standard 1.3 (Thanks to 1iveowl) -* [Server] Added an event to receive every application message - Copyright Christian Kratky 2016-2017 - MQTT MQTTClient MQTTServer MQTTBroker Broker - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index e30c896..0000000 --- a/build.ps1 +++ /dev/null @@ -1,14 +0,0 @@ -param([string]$version) - -if ([string]::IsNullOrEmpty($version)) {$version = "0.0.1"} - -$msbuild = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" -&$msbuild ..\Frameworks\MQTTnet.NetFramework\MQTTnet.NetFramework.csproj /t:Build /p:Configuration="Release" -&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" -&$msbuild ..\Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj /t:Build /p:Configuration="Release" - - - -Remove-Item .\NuGet -Force -Recurse -New-Item -ItemType Directory -Force -Path .\NuGet -.\NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version \ No newline at end of file From 31419fef0392d3938d8157ea267a4ebf4f0a44f5 Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Fri, 14 Jul 2017 08:22:02 +0200 Subject: [PATCH 10/18] Update .gitignore --- .gitignore | 84 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index de42c58..940794e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.suo @@ -15,12 +17,12 @@ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ -[Xx]64/ -[Xx]86/ -[Bb]uild/ +x64/ +x86/ bld/ [Bb]in/ [Oo]bj/ +[Ll]og/ # Visual Studio 2015 cache/options directory .vs/ @@ -40,9 +42,11 @@ TestResult.xml [Rr]eleasePS/ dlldata.c -# DNX +# .NET Core project.lock.json +project.fragment.lock.json artifacts/ +**/Properties/launchSettings.json *_i.c *_p.c @@ -81,6 +85,7 @@ ipch/ *.sdf *.cachefile *.VC.db +*.VC.VC.opendb # Visual Studio profiler *.psess @@ -108,6 +113,10 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch _NCrunch_* .*crunch*.local.xml @@ -139,13 +148,16 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml - -# TODO: Un-comment the next line if you do not want to checkin -# your web deploy settings because they may include unencrypted -# passwords -#*.pubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml *.publishproj +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + # NuGet Packages *.nupkg # The packages folder can be ignored because of Package Restore @@ -154,7 +166,7 @@ publish/ !**/packages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files +# NuGet v3's project.json files produces more ignorable files *.nuget.props *.nuget.targets @@ -166,12 +178,11 @@ csx/ ecf/ rcf/ -# Microsoft Azure ApplicationInsights config file -ApplicationInsights.config - -# Windows Store app package directory +# Windows Store app package directories and files AppPackages/ BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt # Visual Studio cache files # files ending in .cache can be ignored @@ -181,16 +192,19 @@ BundleArtifacts/ # Others ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl *.dbproj.schemaview +*.jfm *.pfx *.publishsettings -node_modules/ orleans.codegen.cs +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + # RIA/Silverlight projects Generated_Code/ @@ -205,6 +219,7 @@ UpgradeLog*.htm # SQL Server files *.mdf *.ldf +*.ndf # Business Intelligence projects *.rdl.data @@ -219,6 +234,10 @@ FakesAssemblies/ # Node.js Tools for Visual Studio .ntvs_analysis.dat +node_modules/ + +# Typescript v1 declaration files +typings/ # Visual Studio 6 build log *.plg @@ -226,6 +245,9 @@ FakesAssemblies/ # Visual Studio 6 workspace options file *.opt +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts @@ -234,13 +256,33 @@ FakesAssemblies/ **/*.Server/ModelManifest.xml _Pvt_Extensions -# LightSwitch generated files -GeneratedArtifacts/ -ModelManifest.xml - # Paket dependency manager .paket/paket.exe +paket-files/ # FAKE - F# Make .fake/ -nuget.exe \ No newline at end of file + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs From b3e11d47b794fa476d0ab39cfc5a095ee0aa43c6 Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Fri, 14 Jul 2017 08:22:11 +0200 Subject: [PATCH 11/18] Build fix --- .gitignore | 84 ++++++++++++++++++++++++++++++++++++------------- Build/build.ps1 | 14 +++++++++ 2 files changed, 77 insertions(+), 21 deletions(-) create mode 100644 Build/build.ps1 diff --git a/.gitignore b/.gitignore index de42c58..940794e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.suo @@ -15,12 +17,12 @@ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ -[Xx]64/ -[Xx]86/ -[Bb]uild/ +x64/ +x86/ bld/ [Bb]in/ [Oo]bj/ +[Ll]og/ # Visual Studio 2015 cache/options directory .vs/ @@ -40,9 +42,11 @@ TestResult.xml [Rr]eleasePS/ dlldata.c -# DNX +# .NET Core project.lock.json +project.fragment.lock.json artifacts/ +**/Properties/launchSettings.json *_i.c *_p.c @@ -81,6 +85,7 @@ ipch/ *.sdf *.cachefile *.VC.db +*.VC.VC.opendb # Visual Studio profiler *.psess @@ -108,6 +113,10 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch _NCrunch_* .*crunch*.local.xml @@ -139,13 +148,16 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml - -# TODO: Un-comment the next line if you do not want to checkin -# your web deploy settings because they may include unencrypted -# passwords -#*.pubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml *.publishproj +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + # NuGet Packages *.nupkg # The packages folder can be ignored because of Package Restore @@ -154,7 +166,7 @@ publish/ !**/packages/build/ # Uncomment if necessary however generally it will be regenerated when needed #!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files +# NuGet v3's project.json files produces more ignorable files *.nuget.props *.nuget.targets @@ -166,12 +178,11 @@ csx/ ecf/ rcf/ -# Microsoft Azure ApplicationInsights config file -ApplicationInsights.config - -# Windows Store app package directory +# Windows Store app package directories and files AppPackages/ BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt # Visual Studio cache files # files ending in .cache can be ignored @@ -181,16 +192,19 @@ BundleArtifacts/ # Others ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl *.dbproj.schemaview +*.jfm *.pfx *.publishsettings -node_modules/ orleans.codegen.cs +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + # RIA/Silverlight projects Generated_Code/ @@ -205,6 +219,7 @@ UpgradeLog*.htm # SQL Server files *.mdf *.ldf +*.ndf # Business Intelligence projects *.rdl.data @@ -219,6 +234,10 @@ FakesAssemblies/ # Node.js Tools for Visual Studio .ntvs_analysis.dat +node_modules/ + +# Typescript v1 declaration files +typings/ # Visual Studio 6 build log *.plg @@ -226,6 +245,9 @@ FakesAssemblies/ # Visual Studio 6 workspace options file *.opt +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + # Visual Studio LightSwitch build output **/*.HTMLClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts @@ -234,13 +256,33 @@ FakesAssemblies/ **/*.Server/ModelManifest.xml _Pvt_Extensions -# LightSwitch generated files -GeneratedArtifacts/ -ModelManifest.xml - # Paket dependency manager .paket/paket.exe +paket-files/ # FAKE - F# Make .fake/ -nuget.exe \ No newline at end of file + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs diff --git a/Build/build.ps1 b/Build/build.ps1 new file mode 100644 index 0000000..322a2c8 --- /dev/null +++ b/Build/build.ps1 @@ -0,0 +1,14 @@ +param([string]$version) + +if ([string]::IsNullOrEmpty($version)) {$version = "0.0.1"} + +$msbuild = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe" +&$msbuild ..\Frameworks\MQTTnet.NetFramework\MQTTnet.NetFramework.csproj /t:Build /p:Configuration="Release" +&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" +&$msbuild ..\Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj /t:Build /p:Configuration="Release" + + + +Remove-Item .\NuGet -Force -Recurse +New-Item -ItemType Directory -Force -Path .\NuGet +NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version \ No newline at end of file From 9c5e5b5e10178df80ba68de13fa614cdf6af388f Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Fri, 14 Jul 2017 08:22:41 +0200 Subject: [PATCH 12/18] build fix --- MQTTnet.sln | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MQTTnet.sln b/MQTTnet.sln index 17e73d0..f6a4ad0 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -17,8 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core", "MQTTnet.Cor EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{002203AF-2565-4C0D-95ED-027FDEFE0C35}" ProjectSection(SolutionItems) = preProject - build.ps1 = build.ps1 - MQTTnet.nuspec = MQTTnet.nuspec + Build\build.ps1 = Build\build.ps1 + Build\MQTTnet.nuspec = Build\MQTTnet.nuspec EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.NetFramework", "Tests\MQTTnet.TestApp.NetFramework\MQTTnet.TestApp.NetFramework.csproj", "{D9D74F33-6943-49B2-B765-7BD589082098}" From 1fb0944e2bc4eb68a6794e851926999a4ad195ea Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Fri, 14 Jul 2017 08:26:03 +0200 Subject: [PATCH 13/18] Folder fix --- .../Implementations/MqttServerAdapter.cs | 117 ----------------- .../Implementations/MqttTcpChannel.cs | 122 ------------------ .../MQTTnet.NetStandard/MqttClientFactory.cs | 18 --- .../MQTTnet.NetStandard/MqttServerFactory.cs | 18 --- .../MQTTnet.Netstandard.csproj | 21 --- 5 files changed, 296 deletions(-) delete mode 100644 Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs delete mode 100644 Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs delete mode 100644 Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs delete mode 100644 Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs delete mode 100644 Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs deleted file mode 100644 index 0203134..0000000 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Net; -using System.Net.Security; -using System.Net.Sockets; -using System.Security.Authentication; -using System.Security.Cryptography.X509Certificates; -using System.Threading; -using System.Threading.Tasks; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Serializer; -using MQTTnet.Core.Server; - -namespace MQTTnet.Implementations -{ - public class MqttServerAdapter : IMqttServerAdapter, IDisposable - { - private CancellationTokenSource _cancellationTokenSource; - private Socket _defaultEndpointSocket; - private Socket _tlsEndpointSocket; - private X509Certificate2 _tlsCertificate; - - private bool _isRunning; - - public event EventHandler ClientConnected; - - public void Start(MqttServerOptions options) - { - if (_isRunning) throw new InvalidOperationException("Server is already started."); - _isRunning = true; - - _cancellationTokenSource = new CancellationTokenSource(); - - if (options.DefaultEndpointOptions.IsEnabled) - { - _defaultEndpointSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); - _defaultEndpointSocket.Bind(new IPEndPoint(IPAddress.Any, options.GetDefaultEndpointPort())); - _defaultEndpointSocket.Listen(options.ConnectionBacklog); - - Task.Run(() => AcceptDefaultEndpointConnectionsAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token); - } - - if (options.TlsEndpointOptions.IsEnabled) - { - if (options.TlsEndpointOptions.Certificate == null) - { - throw new ArgumentException("TLS certificate is not set."); - } - - _tlsCertificate = new X509Certificate2(options.TlsEndpointOptions.Certificate); - - _tlsEndpointSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); - _tlsEndpointSocket.Bind(new IPEndPoint(IPAddress.Any, options.GetTlsEndpointPort())); - _tlsEndpointSocket.Listen(options.ConnectionBacklog); - - Task.Run(() => AcceptTlsEndpointConnectionsAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token); - } - } - - public void Stop() - { - _isRunning = false; - - _cancellationTokenSource?.Dispose(); - _cancellationTokenSource = null; - - _defaultEndpointSocket?.Dispose(); - _defaultEndpointSocket = null; - - _tlsEndpointSocket?.Dispose(); - _tlsEndpointSocket = null; - } - - public void Dispose() - { - Stop(); - } - - private async Task AcceptDefaultEndpointConnectionsAsync(CancellationToken cancellationToken) - { - while (!cancellationToken.IsCancellationRequested) - { - try - { - var clientSocket = await _defaultEndpointSocket.AcceptAsync(); - var clientAdapter = new MqttChannelCommunicationAdapter(new MqttTcpChannel(clientSocket, null), new DefaultMqttV311PacketSerializer()); - ClientConnected?.Invoke(this, new MqttClientConnectedEventArgs(clientSocket.RemoteEndPoint.ToString(), clientAdapter)); - } - catch (Exception exception) - { - MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while acceping connection at default endpoint."); - } - } - } - - private async Task AcceptTlsEndpointConnectionsAsync(CancellationToken cancellationToken) - { - while (!cancellationToken.IsCancellationRequested) - { - try - { - var clientSocket = await _defaultEndpointSocket.AcceptAsync(); - - var sslStream = new SslStream(new NetworkStream(clientSocket)); - await sslStream.AuthenticateAsServerAsync(_tlsCertificate, false, SslProtocols.Tls12, false); - - var clientAdapter = new MqttChannelCommunicationAdapter(new MqttTcpChannel(clientSocket, sslStream), new DefaultMqttV311PacketSerializer()); - ClientConnected?.Invoke(this, new MqttClientConnectedEventArgs(clientSocket.RemoteEndPoint.ToString(), clientAdapter)); - } - catch (Exception exception) - { - MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while acceping connection at TLS endpoint."); - } - } - } - } -} \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs deleted file mode 100644 index e78cd98..0000000 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System; -using System.Net.Security; -using System.Net.Sockets; -using System.Security.Authentication; -using System.Security.Cryptography.X509Certificates; -using System.Threading.Tasks; -using MQTTnet.Core.Channel; -using MQTTnet.Core.Client; -using MQTTnet.Core.Exceptions; - -namespace MQTTnet.Implementations -{ - public sealed class MqttTcpChannel : IMqttCommunicationChannel, IDisposable - { - private readonly Socket _socket; - private SslStream _sslStream; - - public MqttTcpChannel() - { - _socket = new Socket(SocketType.Stream, ProtocolType.Tcp); - } - - public MqttTcpChannel(Socket socket, SslStream sslStream) - { - _socket = socket ?? throw new ArgumentNullException(nameof(socket)); - _sslStream = sslStream; - } - - public async Task ConnectAsync(MqttClientOptions options) - { - if (options == null) throw new ArgumentNullException(nameof(options)); - try - { - await _socket.ConnectAsync(options.Server, options.GetPort()); - - if (options.TlsOptions.UseTls) - { - _sslStream = new SslStream(new NetworkStream(_socket, true)); - await _sslStream.AuthenticateAsClientAsync(options.Server, LoadCertificates(options), SslProtocols.Tls12, options.TlsOptions.CheckCertificateRevocation); - } - } - catch (SocketException exception) - { - throw new MqttCommunicationException(exception); - } - } - - public Task DisconnectAsync() - { - try - { - _sslStream.Dispose(); - _socket.Dispose(); - return Task.FromResult(0); - } - catch (SocketException exception) - { - throw new MqttCommunicationException(exception); - } - } - - public Task WriteAsync(byte[] buffer) - { - if (buffer == null) throw new ArgumentNullException(nameof(buffer)); - - try - { - if (_sslStream != null) - { - return _sslStream.WriteAsync(buffer, 0, buffer.Length); - } - - return _socket.SendAsync(new ArraySegment(buffer), SocketFlags.None); - } - catch (SocketException exception) - { - throw new MqttCommunicationException(exception); - } - } - - public Task ReadAsync(byte[] buffer) - { - if (buffer == null) throw new ArgumentNullException(nameof(buffer)); - - try - { - if (_sslStream != null) - { - return _sslStream.ReadAsync(buffer, 0, buffer.Length); - } - - return _socket.ReceiveAsync(new ArraySegment(buffer), SocketFlags.None); - } - catch (SocketException exception) - { - throw new MqttCommunicationException(exception); - } - } - - public void Dispose() - { - _socket?.Dispose(); - _sslStream?.Dispose(); - } - - private static X509CertificateCollection LoadCertificates(MqttClientOptions options) - { - var certificates = new X509CertificateCollection(); - if (options.TlsOptions.Certificates == null) - { - return certificates; - } - - foreach (var certificate in options.TlsOptions.Certificates) - { - certificates.Add(new X509Certificate(certificate)); - } - - return certificates; - } - } -} \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs deleted file mode 100644 index ac6f611..0000000 --- a/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Client; -using MQTTnet.Core.Serializer; -using MQTTnet.Implementations; - -namespace MQTTnet -{ - public class MqttClientFactory - { - public MqttClient CreateMqttClient(MqttClientOptions options) - { - if (options == null) throw new ArgumentNullException(nameof(options)); - - return new MqttClient(options, new MqttChannelCommunicationAdapter(new MqttTcpChannel(), new DefaultMqttV311PacketSerializer())); - } - } -} diff --git a/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs deleted file mode 100644 index eb7441c..0000000 --- a/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Server; -using MQTTnet.Implementations; - -namespace MQTTnet -{ - public class MqttServerFactory - { - public MqttServer CreateMqttServer(MqttServerOptions options) - { - if (options == null) throw new ArgumentNullException(nameof(options)); - - return new MqttServer(options, new List { new MqttServerAdapter() }); - } - } -} diff --git a/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj deleted file mode 100644 index 10ffeed..0000000 --- a/Frameworks/MQTTnet.Netstandard/MQTTnet.Netstandard.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - netstandard1.3 - MQTTnet - MQTTnet - - - - - - - - - - - - - - - \ No newline at end of file From 3722bc9ae6409c5c9158ea51f286a77631530876 Mon Sep 17 00:00:00 2001 From: 1iveowl Date: Fri, 14 Jul 2017 08:26:25 +0200 Subject: [PATCH 14/18] Folder fix --- .../Implementations/MqttServerAdapter.cs | 117 +++++++++++++++++ .../Implementations/MqttTcpChannel.cs | 122 ++++++++++++++++++ .../MQTTnet.Netstandard.csproj | 21 +++ .../MQTTnet.NetStandard/MqttClientFactory.cs | 18 +++ .../MQTTnet.NetStandard/MqttServerFactory.cs | 18 +++ 5 files changed, 296 insertions(+) create mode 100644 Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs create mode 100644 Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs create mode 100644 Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj create mode 100644 Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs create mode 100644 Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs new file mode 100644 index 0000000..0203134 --- /dev/null +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs @@ -0,0 +1,117 @@ +using System; +using System.Net; +using System.Net.Security; +using System.Net.Sockets; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; +using System.Threading; +using System.Threading.Tasks; +using MQTTnet.Core.Adapter; +using MQTTnet.Core.Diagnostics; +using MQTTnet.Core.Serializer; +using MQTTnet.Core.Server; + +namespace MQTTnet.Implementations +{ + public class MqttServerAdapter : IMqttServerAdapter, IDisposable + { + private CancellationTokenSource _cancellationTokenSource; + private Socket _defaultEndpointSocket; + private Socket _tlsEndpointSocket; + private X509Certificate2 _tlsCertificate; + + private bool _isRunning; + + public event EventHandler ClientConnected; + + public void Start(MqttServerOptions options) + { + if (_isRunning) throw new InvalidOperationException("Server is already started."); + _isRunning = true; + + _cancellationTokenSource = new CancellationTokenSource(); + + if (options.DefaultEndpointOptions.IsEnabled) + { + _defaultEndpointSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); + _defaultEndpointSocket.Bind(new IPEndPoint(IPAddress.Any, options.GetDefaultEndpointPort())); + _defaultEndpointSocket.Listen(options.ConnectionBacklog); + + Task.Run(() => AcceptDefaultEndpointConnectionsAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token); + } + + if (options.TlsEndpointOptions.IsEnabled) + { + if (options.TlsEndpointOptions.Certificate == null) + { + throw new ArgumentException("TLS certificate is not set."); + } + + _tlsCertificate = new X509Certificate2(options.TlsEndpointOptions.Certificate); + + _tlsEndpointSocket = new Socket(SocketType.Stream, ProtocolType.Tcp); + _tlsEndpointSocket.Bind(new IPEndPoint(IPAddress.Any, options.GetTlsEndpointPort())); + _tlsEndpointSocket.Listen(options.ConnectionBacklog); + + Task.Run(() => AcceptTlsEndpointConnectionsAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token); + } + } + + public void Stop() + { + _isRunning = false; + + _cancellationTokenSource?.Dispose(); + _cancellationTokenSource = null; + + _defaultEndpointSocket?.Dispose(); + _defaultEndpointSocket = null; + + _tlsEndpointSocket?.Dispose(); + _tlsEndpointSocket = null; + } + + public void Dispose() + { + Stop(); + } + + private async Task AcceptDefaultEndpointConnectionsAsync(CancellationToken cancellationToken) + { + while (!cancellationToken.IsCancellationRequested) + { + try + { + var clientSocket = await _defaultEndpointSocket.AcceptAsync(); + var clientAdapter = new MqttChannelCommunicationAdapter(new MqttTcpChannel(clientSocket, null), new DefaultMqttV311PacketSerializer()); + ClientConnected?.Invoke(this, new MqttClientConnectedEventArgs(clientSocket.RemoteEndPoint.ToString(), clientAdapter)); + } + catch (Exception exception) + { + MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while acceping connection at default endpoint."); + } + } + } + + private async Task AcceptTlsEndpointConnectionsAsync(CancellationToken cancellationToken) + { + while (!cancellationToken.IsCancellationRequested) + { + try + { + var clientSocket = await _defaultEndpointSocket.AcceptAsync(); + + var sslStream = new SslStream(new NetworkStream(clientSocket)); + await sslStream.AuthenticateAsServerAsync(_tlsCertificate, false, SslProtocols.Tls12, false); + + var clientAdapter = new MqttChannelCommunicationAdapter(new MqttTcpChannel(clientSocket, sslStream), new DefaultMqttV311PacketSerializer()); + ClientConnected?.Invoke(this, new MqttClientConnectedEventArgs(clientSocket.RemoteEndPoint.ToString(), clientAdapter)); + } + catch (Exception exception) + { + MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while acceping connection at TLS endpoint."); + } + } + } + } +} \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs new file mode 100644 index 0000000..e78cd98 --- /dev/null +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs @@ -0,0 +1,122 @@ +using System; +using System.Net.Security; +using System.Net.Sockets; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using MQTTnet.Core.Channel; +using MQTTnet.Core.Client; +using MQTTnet.Core.Exceptions; + +namespace MQTTnet.Implementations +{ + public sealed class MqttTcpChannel : IMqttCommunicationChannel, IDisposable + { + private readonly Socket _socket; + private SslStream _sslStream; + + public MqttTcpChannel() + { + _socket = new Socket(SocketType.Stream, ProtocolType.Tcp); + } + + public MqttTcpChannel(Socket socket, SslStream sslStream) + { + _socket = socket ?? throw new ArgumentNullException(nameof(socket)); + _sslStream = sslStream; + } + + public async Task ConnectAsync(MqttClientOptions options) + { + if (options == null) throw new ArgumentNullException(nameof(options)); + try + { + await _socket.ConnectAsync(options.Server, options.GetPort()); + + if (options.TlsOptions.UseTls) + { + _sslStream = new SslStream(new NetworkStream(_socket, true)); + await _sslStream.AuthenticateAsClientAsync(options.Server, LoadCertificates(options), SslProtocols.Tls12, options.TlsOptions.CheckCertificateRevocation); + } + } + catch (SocketException exception) + { + throw new MqttCommunicationException(exception); + } + } + + public Task DisconnectAsync() + { + try + { + _sslStream.Dispose(); + _socket.Dispose(); + return Task.FromResult(0); + } + catch (SocketException exception) + { + throw new MqttCommunicationException(exception); + } + } + + public Task WriteAsync(byte[] buffer) + { + if (buffer == null) throw new ArgumentNullException(nameof(buffer)); + + try + { + if (_sslStream != null) + { + return _sslStream.WriteAsync(buffer, 0, buffer.Length); + } + + return _socket.SendAsync(new ArraySegment(buffer), SocketFlags.None); + } + catch (SocketException exception) + { + throw new MqttCommunicationException(exception); + } + } + + public Task ReadAsync(byte[] buffer) + { + if (buffer == null) throw new ArgumentNullException(nameof(buffer)); + + try + { + if (_sslStream != null) + { + return _sslStream.ReadAsync(buffer, 0, buffer.Length); + } + + return _socket.ReceiveAsync(new ArraySegment(buffer), SocketFlags.None); + } + catch (SocketException exception) + { + throw new MqttCommunicationException(exception); + } + } + + public void Dispose() + { + _socket?.Dispose(); + _sslStream?.Dispose(); + } + + private static X509CertificateCollection LoadCertificates(MqttClientOptions options) + { + var certificates = new X509CertificateCollection(); + if (options.TlsOptions.Certificates == null) + { + return certificates; + } + + foreach (var certificate in options.TlsOptions.Certificates) + { + certificates.Add(new X509Certificate(certificate)); + } + + return certificates; + } + } +} \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj new file mode 100644 index 0000000..10ffeed --- /dev/null +++ b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj @@ -0,0 +1,21 @@ + + + + netstandard1.3 + MQTTnet + MQTTnet + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs new file mode 100644 index 0000000..ac6f611 --- /dev/null +++ b/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs @@ -0,0 +1,18 @@ +using System; +using MQTTnet.Core.Adapter; +using MQTTnet.Core.Client; +using MQTTnet.Core.Serializer; +using MQTTnet.Implementations; + +namespace MQTTnet +{ + public class MqttClientFactory + { + public MqttClient CreateMqttClient(MqttClientOptions options) + { + if (options == null) throw new ArgumentNullException(nameof(options)); + + return new MqttClient(options, new MqttChannelCommunicationAdapter(new MqttTcpChannel(), new DefaultMqttV311PacketSerializer())); + } + } +} diff --git a/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs new file mode 100644 index 0000000..eb7441c --- /dev/null +++ b/Frameworks/MQTTnet.NetStandard/MqttServerFactory.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using MQTTnet.Core.Adapter; +using MQTTnet.Core.Server; +using MQTTnet.Implementations; + +namespace MQTTnet +{ + public class MqttServerFactory + { + public MqttServer CreateMqttServer(MqttServerOptions options) + { + if (options == null) throw new ArgumentNullException(nameof(options)); + + return new MqttServer(options, new List { new MqttServerAdapter() }); + } + } +} From 5a1d953278a3f3282f70c6ac7616803108f5adf4 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 15 Jul 2017 10:11:03 +0200 Subject: [PATCH 15/18] Move build files to build folder --- .gitignore | 1 - Build/MQTTnet.nuspec | 3 ++- Build/build.ps1 | 12 ++++++++++++ MQTTnet.sln | 12 ++++++------ 4 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 Build/build.ps1 diff --git a/.gitignore b/.gitignore index de42c58..4ef66c4 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ [Rr]eleases/ [Xx]64/ [Xx]86/ -[Bb]uild/ bld/ [Bb]in/ [Oo]bj/ diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index c418fba..c6845fe 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -10,7 +10,8 @@ https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png false MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). - * [.NET Standard] Added support for .NET Standard 1.3 (Thanks to 1iveowl) + * [.NET Standard] Added support for .NET Standard 1.3 (Thanks to 1iveowl) +* [Server] Added an even which allows processing of all received messages from the clients Copyright Christian Kratky 2016-2017 MQTT MQTTClient MQTTServer MQTTBroker Broker diff --git a/Build/build.ps1 b/Build/build.ps1 new file mode 100644 index 0000000..b8e71b1 --- /dev/null +++ b/Build/build.ps1 @@ -0,0 +1,12 @@ +param([string]$version) + +if ([string]::IsNullOrEmpty($version)) {$version = "0.0.1"} + +$msbuild = "MSBuild.exe" +&$msbuild ..\Frameworks\MQTTnet.NetFramework\MQTTnet.NetFramework.csproj /t:Build /p:Configuration="Release" +&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" +&$msbuild ..\Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj /t:Build /p:Configuration="Release" + +Remove-Item .\NuGet -Force -Recurse +New-Item -ItemType Directory -Force -Path .\NuGet +.\NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version \ No newline at end of file diff --git a/MQTTnet.sln b/MQTTnet.sln index 17e73d0..697f504 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -15,18 +15,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frameworks", "Frameworks", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core", "MQTTnet.Core\MQTTnet.Core.csproj", "{2ECB99E4-72D0-4C23-99BA-93D511D3967D}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{002203AF-2565-4C0D-95ED-027FDEFE0C35}" - ProjectSection(SolutionItems) = preProject - build.ps1 = build.ps1 - MQTTnet.nuspec = MQTTnet.nuspec - EndProjectSection -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.NetFramework", "Tests\MQTTnet.TestApp.NetFramework\MQTTnet.TestApp.NetFramework.csproj", "{D9D74F33-6943-49B2-B765-7BD589082098}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.TestApp.UniversalWindows", "Tests\MQTTnet.TestApp.UniversalWindows\MQTTnet.TestApp.UniversalWindows.csproj", "{FF1F72D6-9524-4422-9497-3CC0002216ED}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.NetStandard", "Frameworks\MQTTnet.Netstandard\MQTTnet.NetStandard.csproj", "{3587E506-55A2-4EB3-99C7-DC01E42D25D2}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{67C28AC1-BC3A-420A-BE9C-FA2401431CF9}" + ProjectSection(SolutionItems) = preProject + Build\build.ps1 = Build\build.ps1 + Build\MQTTnet.nuspec = Build\MQTTnet.nuspec + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU From 2193281c6a67d83d30b37b781b1d82f190b73def Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 15 Jul 2017 18:36:09 +0200 Subject: [PATCH 16/18] Add version information for next release --- Build/MQTTnet.nuspec | 2 +- .../Properties/AssemblyInfo.cs | 4 +-- .../MQTTnet.Netstandard.csproj | 8 ++++++ .../Properties/AssemblyInfo.cs | 4 +-- MQTTnet.Core/MQTTnet.Core.csproj | 28 +++++++++---------- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index c6845fe..e3e529e 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -2,7 +2,7 @@ MQTTnet - 0 + 2.1.4 Christian Kratky Christian Kratky https://github.com/chkr1011/MQTTnet/blob/master/LICENSE diff --git a/Frameworks/MQTTnet.NetFramework/Properties/AssemblyInfo.cs b/Frameworks/MQTTnet.NetFramework/Properties/AssemblyInfo.cs index 24471d2..4d0a57f 100644 --- a/Frameworks/MQTTnet.NetFramework/Properties/AssemblyInfo.cs +++ b/Frameworks/MQTTnet.NetFramework/Properties/AssemblyInfo.cs @@ -11,5 +11,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("a480ef90-0eaa-4d9a-b271-47a9c47f6f7d")] -[assembly: AssemblyVersion("2.1.1.0")] -[assembly: AssemblyFileVersion("2.1.1.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.1.4.0")] +[assembly: AssemblyFileVersion("2.1.4.0")] \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj index 10ffeed..2a60e55 100644 --- a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj @@ -4,6 +4,14 @@ netstandard1.3 MQTTnet MQTTnet + 2.1.4.0 + 2.1.4.0 + 0.0.0.0 + + + + + diff --git a/Frameworks/MQTTnet.UniversalWindows/Properties/AssemblyInfo.cs b/Frameworks/MQTTnet.UniversalWindows/Properties/AssemblyInfo.cs index 7ad7d87..dee61f7 100644 --- a/Frameworks/MQTTnet.UniversalWindows/Properties/AssemblyInfo.cs +++ b/Frameworks/MQTTnet.UniversalWindows/Properties/AssemblyInfo.cs @@ -10,5 +10,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] -[assembly: AssemblyVersion("2.1.1.0")] -[assembly: AssemblyFileVersion("2.1.1.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.1.4.0")] +[assembly: AssemblyFileVersion("2.1.4.0")] \ No newline at end of file diff --git a/MQTTnet.Core/MQTTnet.Core.csproj b/MQTTnet.Core/MQTTnet.Core.csproj index 1b8346d..4d12864 100644 --- a/MQTTnet.Core/MQTTnet.Core.csproj +++ b/MQTTnet.Core/MQTTnet.Core.csproj @@ -5,20 +5,20 @@ MQTTnet.Core MQTTnet.Core False - MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). - MQTTnet - Christian Kratky - Christian Kratky - 2.1.2.0 - MQTTnet.Core - Copyright © Christian Kratky 2016-2017 - https://github.com/chkr1011/MQTTnet - https://raw.githubusercontent.com/chkr1011/MQTTnet/master/Images/Logo_128x128.png - https://github.com/chkr1011/MQTTnet - MQTT MQTTClient MQTTServer MQTTBroker Broker - 2.1.2.0 - 2.1.2.0 - https://github.com/chkr1011/MQTTnet/blob/master/LICENSE + + + + + 0.0.0.0 + + + + + + + 2.1.4.0 + 2.1.4.0 + From 886b2d6b42854f73c283571daabb1ded42399f2c Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 15 Jul 2017 18:36:33 +0200 Subject: [PATCH 17/18] Fix issue when stopping server --- .../Implementations/MqttServerAdapter.cs | 3 ++- .../MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs | 1 + MQTTnet.Core/Client/MqttClient.cs | 5 ++++- MQTTnet.Core/Server/MqttServer.cs | 3 ++- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Frameworks/MQTTnet.NetFramework/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetFramework/Implementations/MqttServerAdapter.cs index f739756..cbfcf66 100644 --- a/Frameworks/MQTTnet.NetFramework/Implementations/MqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetFramework/Implementations/MqttServerAdapter.cs @@ -63,6 +63,7 @@ namespace MQTTnet.Implementations { _isRunning = false; + _cancellationTokenSource?.Cancel(false); _cancellationTokenSource?.Dispose(); _cancellationTokenSource = null; @@ -88,7 +89,7 @@ namespace MQTTnet.Implementations var clientAdapter = new MqttChannelCommunicationAdapter(new MqttTcpChannel(clientSocket, null), new DefaultMqttV311PacketSerializer()); ClientConnected?.Invoke(this, new MqttClientConnectedEventArgs(clientSocket.RemoteEndPoint.ToString(), clientAdapter)); } - catch (Exception exception) + catch (Exception exception) when (!(exception is ObjectDisposedException)) { MqttTrace.Error(nameof(MqttServerAdapter), exception, "Error while acceping connection at default endpoint."); } diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs index 0203134..863d3e7 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs @@ -61,6 +61,7 @@ namespace MQTTnet.Implementations { _isRunning = false; + _cancellationTokenSource?.Cancel(false); _cancellationTokenSource?.Dispose(); _cancellationTokenSource = null; diff --git a/MQTTnet.Core/Client/MqttClient.cs b/MQTTnet.Core/Client/MqttClient.cs index ebf2cfd..df3c61f 100644 --- a/MQTTnet.Core/Client/MqttClient.cs +++ b/MQTTnet.Core/Client/MqttClient.cs @@ -185,7 +185,10 @@ namespace MQTTnet.Core.Client } finally { - _cancellationTokenSource?.Cancel(); + _cancellationTokenSource?.Cancel(false); + _cancellationTokenSource?.Dispose(); + _cancellationTokenSource = null; + IsConnected = false; Disconnected?.Invoke(this, EventArgs.Empty); } diff --git a/MQTTnet.Core/Server/MqttServer.cs b/MQTTnet.Core/Server/MqttServer.cs index f7f7932..ca55d7a 100644 --- a/MQTTnet.Core/Server/MqttServer.cs +++ b/MQTTnet.Core/Server/MqttServer.cs @@ -59,7 +59,8 @@ namespace MQTTnet.Core.Server public void Stop() { - _cancellationTokenSource?.Cancel(); + _cancellationTokenSource?.Cancel(false); + _cancellationTokenSource?.Dispose(); _cancellationTokenSource = null; foreach (var adapter in _adapters) From 8cfdb2fbf2ae5e5b5d47f3669db3668266de7d28 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sat, 15 Jul 2017 18:37:22 +0200 Subject: [PATCH 18/18] Update release notes --- Build/MQTTnet.nuspec | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index e3e529e..2211891 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -11,7 +11,9 @@ false MQTTnet is a .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). * [.NET Standard] Added support for .NET Standard 1.3 (Thanks to 1iveowl) -* [Server] Added an even which allows processing of all received messages from the clients +* [Server] Added an even which allows processing of all received messages from the clients +* [Server] Fixed an issue when stopping the server + Copyright Christian Kratky 2016-2017 MQTT MQTTClient MQTTServer MQTTBroker Broker