diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index d6f72810..c7a9b86d 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -48,8 +48,8 @@ - - + + \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetFramework/Implementations/MqttCommunicationAdapterFactory.cs b/Frameworks/MQTTnet.NetFramework/Implementations/MqttCommunicationAdapterFactory.cs deleted file mode 100644 index 799ccddd..00000000 --- a/Frameworks/MQTTnet.NetFramework/Implementations/MqttCommunicationAdapterFactory.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using MQTTnet.Core.Adapter; -using MQTTnet.Core.Client; -using MQTTnet.Core.Serializer; - -namespace MQTTnet.Implementations -{ - public class MqttCommunicationAdapterFactory : IMqttCommunicationAdapterFactory - { - public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(MqttClientOptions options) - { - if (options == null) throw new ArgumentNullException(nameof(options)); - - if (options is MqttClientTcpOptions tcpOptions) - { - return new MqttChannelCommunicationAdapter(new MqttTcpChannel(tcpOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion }); - } - - if (options is MqttClientWebSocketOptions webSocketOptions) - { - return new MqttChannelCommunicationAdapter(new MqttWebSocketChannel(webSocketOptions), new MqttPacketSerializer { ProtocolVersion = options.ProtocolVersion }); - } - - throw new NotSupportedException(); - } - } -} \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetFramework/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetFramework/Implementations/MqttServerAdapter.cs deleted file mode 100644 index c6df6efc..00000000 --- a/Frameworks/MQTTnet.NetFramework/Implementations/MqttServerAdapter.cs +++ /dev/null @@ -1,133 +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 Action ClientAccepted; - - public Task StartAsync(MqttServerOptions options) - { - if (options == null) throw new ArgumentNullException(nameof(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); - } - - return Task.FromResult(0); - } - - public Task StopAsync() - { - _isRunning = false; - - _cancellationTokenSource?.Cancel(false); - _cancellationTokenSource?.Dispose(); - _cancellationTokenSource = null; - - _defaultEndpointSocket?.Dispose(); - _defaultEndpointSocket = null; - - _tlsEndpointSocket?.Dispose(); - _tlsEndpointSocket = null; - - return Task.FromResult(0); - } - - public void Dispose() - { - StopAsync(); - } - - private async Task AcceptDefaultEndpointConnectionsAsync(CancellationToken cancellationToken) - { - while (!cancellationToken.IsCancellationRequested) - { - try - { - var clientSocket = await Task.Factory.FromAsync(_defaultEndpointSocket.BeginAccept, _defaultEndpointSocket.EndAccept, null).ConfigureAwait(false); - - var tcpChannel = new MqttTcpChannel(clientSocket, null); - var clientAdapter = new MqttChannelCommunicationAdapter(tcpChannel, new MqttPacketSerializer()); - ClientAccepted?.Invoke(clientAdapter); - } - catch (Exception exception) when (!(exception is ObjectDisposedException)) - { - MqttNetTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at default endpoint."); - - //excessive CPU consumed if in endless loop of socket errors - await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); - } - } - } - - private async Task AcceptTlsEndpointConnectionsAsync(CancellationToken cancellationToken) - { - while (!cancellationToken.IsCancellationRequested) - { - try - { - var clientSocket = await Task.Factory.FromAsync(_tlsEndpointSocket.BeginAccept, _tlsEndpointSocket.EndAccept, null).ConfigureAwait(false); - - var sslStream = new SslStream(new NetworkStream(clientSocket)); - await sslStream.AuthenticateAsServerAsync(_tlsCertificate, false, SslProtocols.Tls12, false).ConfigureAwait(false); - - var tcpChannel = new MqttTcpChannel(clientSocket, sslStream); - var clientAdapter = new MqttChannelCommunicationAdapter(tcpChannel, new MqttPacketSerializer()); - ClientAccepted?.Invoke(clientAdapter); - } - catch (Exception exception) - { - MqttNetTrace.Error(nameof(MqttServerAdapter), exception, "Error while accepting connection at TLS endpoint."); - - //excessive CPU consumed if in endless loop of socket errors - await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken).ConfigureAwait(false); - } - } - } - } -} \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetFramework/Implementations/MqttTcpChannel.cs b/Frameworks/MQTTnet.NetFramework/Implementations/MqttTcpChannel.cs deleted file mode 100644 index 6f9375ef..00000000 --- a/Frameworks/MQTTnet.NetFramework/Implementations/MqttTcpChannel.cs +++ /dev/null @@ -1,150 +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 System.IO; -using System.Linq; - -namespace MQTTnet.Implementations -{ - public sealed class MqttTcpChannel : IMqttCommunicationChannel, IDisposable - { - private readonly MqttClientTcpOptions _options; - - // ReSharper disable once MemberCanBePrivate.Global - // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global - public static int BufferSize { get; set; } = 4096 * 20; // Can be changed for fine tuning by library user. - - private Socket _socket; - private SslStream _sslStream; - - /// - /// called on client sockets are created in connect - /// - public MqttTcpChannel(MqttClientTcpOptions options) - { - _options = options ?? throw new ArgumentNullException(nameof(options)); - } - - /// - /// called on server, sockets are passed in - /// connect will not be called - /// - public MqttTcpChannel(Socket socket, SslStream sslStream) - { - _socket = socket ?? throw new ArgumentNullException(nameof(socket)); - _sslStream = sslStream; - - CreateStreams(socket, sslStream); - } - - public Stream SendStream { get; private set; } - public Stream ReceiveStream { get; private set; } - public Stream RawReceiveStream { get; private set; } - - public static Func CustomCertificateValidationCallback { get; set; } - - public async Task ConnectAsync() - { - if (_socket == null) - { - _socket = new Socket(SocketType.Stream, ProtocolType.Tcp); - } - - await Task.Factory.FromAsync(_socket.BeginConnect, _socket.EndConnect, _options.Server, _options.GetPort(), null).ConfigureAwait(false); - - if (_options.TlsOptions.UseTls) - { - _sslStream = new SslStream(new NetworkStream(_socket, true), false, InternalUserCertificateValidationCallback); - await _sslStream.AuthenticateAsClientAsync(_options.Server, LoadCertificates(_options), SslProtocols.Tls12, _options.TlsOptions.IgnoreCertificateRevocationErrors).ConfigureAwait(false); - } - - CreateStreams(_socket, _sslStream); - } - - public Task DisconnectAsync() - { - Dispose(); - return Task.FromResult(0); - } - - public void Dispose() - { - RawReceiveStream?.Dispose(); - RawReceiveStream = null; - - ReceiveStream?.Dispose(); - ReceiveStream = null; - - SendStream?.Dispose(); - SendStream = null; - - _socket?.Dispose(); - _socket = null; - - _sslStream?.Dispose(); - _sslStream = null; - } - - private void CreateStreams(Socket socket, Stream sslStream) - { - RawReceiveStream = sslStream ?? new NetworkStream(socket); - - //cannot use this as default buffering prevents from receiving the first connect message - //need two streams otherwise read and write have to be synchronized - SendStream = new BufferedStream(RawReceiveStream, BufferSize); - ReceiveStream = new BufferedStream(RawReceiveStream, BufferSize); - } - - private bool InternalUserCertificateValidationCallback(object sender, X509Certificate x509Certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) - { - if (CustomCertificateValidationCallback != null) - { - return CustomCertificateValidationCallback(x509Certificate, chain, sslPolicyErrors, _options); - } - - if (sslPolicyErrors == SslPolicyErrors.None) - { - return true; - } - - if (chain.ChainStatus.Any(c => c.Status == X509ChainStatusFlags.RevocationStatusUnknown || c.Status == X509ChainStatusFlags.Revoked || c.Status == X509ChainStatusFlags.RevocationStatusUnknown)) - { - if (!_options.TlsOptions.IgnoreCertificateRevocationErrors) - { - return false; - } - } - - if (chain.ChainStatus.Any(c => c.Status == X509ChainStatusFlags.PartialChain)) - { - if (!_options.TlsOptions.IgnoreCertificateChainErrors) - { - return false; - } - } - - return _options.TlsOptions.AllowUntrustedCertificates; - } - - 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.NetFramework/Implementations/MqttWebSocketChannel.cs b/Frameworks/MQTTnet.NetFramework/Implementations/MqttWebSocketChannel.cs deleted file mode 100644 index d6c92ac9..00000000 --- a/Frameworks/MQTTnet.NetFramework/Implementations/MqttWebSocketChannel.cs +++ /dev/null @@ -1,57 +0,0 @@ -using MQTTnet.Core.Channel; -using MQTTnet.Core.Client; -using System; -using System.IO; -using System.Net.WebSockets; -using System.Threading; -using System.Threading.Tasks; - -namespace MQTTnet.Implementations -{ - public sealed class MqttWebSocketChannel : IMqttCommunicationChannel, IDisposable - { - private readonly MqttClientWebSocketOptions _options; - - private ClientWebSocket _webSocket; - - public MqttWebSocketChannel(MqttClientWebSocketOptions options) - { - _options = options ?? throw new ArgumentNullException(nameof(options)); - } - - public Stream RawReceiveStream { get; private set; } - public Stream SendStream => RawReceiveStream; - public Stream ReceiveStream => RawReceiveStream; - - public async Task ConnectAsync() - { - var uri = _options.Uri; - if (!uri.StartsWith("ws://", StringComparison.OrdinalIgnoreCase)) - { - uri = "ws://" + uri; - } - - _webSocket = new ClientWebSocket(); - _webSocket.Options.KeepAliveInterval = _options.KeepAlivePeriod; - await _webSocket.ConnectAsync(new Uri(uri), CancellationToken.None).ConfigureAwait(false); - RawReceiveStream = new WebSocketStream(_webSocket); - } - - public async Task DisconnectAsync() - { - RawReceiveStream = null; - - if (_webSocket == null) - { - return; - } - - await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).ConfigureAwait(false); - } - - public void Dispose() - { - _webSocket?.Dispose(); - } - } -} \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetFramework/Implementations/WebSocketStream.cs b/Frameworks/MQTTnet.NetFramework/Implementations/WebSocketStream.cs deleted file mode 100644 index 4f059360..00000000 --- a/Frameworks/MQTTnet.NetFramework/Implementations/WebSocketStream.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.IO; -using System.Net.WebSockets; -using System.Threading; -using System.Threading.Tasks; - -namespace MQTTnet.Implementations -{ - public class WebSocketStream : Stream - { - private readonly ClientWebSocket _webSocket; - - public WebSocketStream(ClientWebSocket webSocket) - { - _webSocket = webSocket; - } - - public override void Flush() - { - } - - public override async Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - var currentOffset = offset; - var targetOffset = offset + count; - while (_webSocket.State == WebSocketState.Open && currentOffset < targetOffset) - { - var response = await _webSocket.ReceiveAsync(new ArraySegment(buffer, currentOffset, count), cancellationToken).ConfigureAwait(false); - currentOffset += response.Count; - - if (response.MessageType == WebSocketMessageType.Close) - { - await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, cancellationToken).ConfigureAwait(false); - } - } - - return currentOffset - offset; - } - - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - return _webSocket.SendAsync(new ArraySegment(buffer, offset, count), WebSocketMessageType.Binary, true, cancellationToken); - } - - public override int Read(byte[] buffer, int offset, int count) - { - return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); - } - - public override void Write(byte[] buffer, int offset, int count) - { - WriteAsync(buffer, offset, count).GetAwaiter().GetResult(); - } - - public override bool CanRead => true; - public override bool CanSeek => false; - public override bool CanWrite => true; - - public override long Length => throw new NotSupportedException(); - - public override long Position - { - get => throw new NotSupportedException(); - set => throw new NotSupportedException(); - } - - public override long Seek(long offset, SeekOrigin origin) - { - throw new NotSupportedException(); - } - - public override void SetLength(long value) - { - throw new NotSupportedException(); - } - } -} diff --git a/Frameworks/MQTTnet.NetFramework/MQTTnet.NetFramework.csproj b/Frameworks/MQTTnet.NetFramework/MQTTnet.NetFramework.csproj deleted file mode 100644 index 22d50325..00000000 --- a/Frameworks/MQTTnet.NetFramework/MQTTnet.NetFramework.csproj +++ /dev/null @@ -1,126 +0,0 @@ - - - - - Debug - AnyCPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D} - Library - Properties - MQTTnet - MQTTnet - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - bin\Any CPU\ - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - true - bin\x86\Debug\ - DEBUG;TRACE - full - x86 - prompt - MinimumRecommendedRules.ruleset - - - bin\x86\Release\ - TRACE - true - pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - - - bin\x86\Any CPU\ - TRACE - true - pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - MinimumRecommendedRules.ruleset - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - - - bin\x64\Any CPU\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - - - - - - - - - - - - - - - - - - {2ecb99e4-72d0-4c23-99ba-93d511d3967d} - MQTTnet.Core - - - - - \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetFramework/MqttClientFactory.cs b/Frameworks/MQTTnet.NetFramework/MqttClientFactory.cs deleted file mode 100644 index 15da033d..00000000 --- a/Frameworks/MQTTnet.NetFramework/MqttClientFactory.cs +++ /dev/null @@ -1,13 +0,0 @@ -using MQTTnet.Core.Client; -using MQTTnet.Implementations; - -namespace MQTTnet -{ - public class MqttClientFactory : IMqttClientFactory - { - public IMqttClient CreateMqttClient() - { - return new MqttClient(new MqttCommunicationAdapterFactory()); - } - } -} \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetFramework/MqttServerFactory.cs b/Frameworks/MQTTnet.NetFramework/MqttServerFactory.cs deleted file mode 100644 index 70e14f3c..00000000 --- a/Frameworks/MQTTnet.NetFramework/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 : IMqttServerFactory - { - public IMqttServer CreateMqttServer(MqttServerOptions options) - { - if (options == null) throw new ArgumentNullException(nameof(options)); - - return new MqttServer(options, new List { new MqttServerAdapter() }); - } - } -} diff --git a/Frameworks/MQTTnet.NetFramework/Properties/AssemblyInfo.cs b/Frameworks/MQTTnet.NetFramework/Properties/AssemblyInfo.cs deleted file mode 100644 index 4307dbcf..00000000 --- a/Frameworks/MQTTnet.NetFramework/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("MQTTnet")] -[assembly: AssemblyDescription("MQTTnet for .NET Framework")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Christian Kratky")] -[assembly: AssemblyProduct("MQTTnet")] -[assembly: AssemblyCopyright("Copyright © Christian Kratky 2016-2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("a480ef90-0eaa-4d9a-b271-47a9c47f6f7d")] -[assembly: AssemblyVersion("2.4.0.0")] -[assembly: AssemblyFileVersion("2.4.0.0")] \ No newline at end of file diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs index 56650dde..a140ca0f 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttServerAdapter.cs @@ -88,7 +88,11 @@ namespace MQTTnet.Implementations { try { +#if NET45 + var clientSocket = await Task.Factory.FromAsync(_defaultEndpointSocket.BeginAccept, _defaultEndpointSocket.EndAccept, null).ConfigureAwait(false); +#else var clientSocket = await _defaultEndpointSocket.AcceptAsync().ConfigureAwait(false); +#endif var clientAdapter = new MqttChannelCommunicationAdapter(new MqttTcpChannel(clientSocket, null), new MqttPacketSerializer()); ClientAccepted?.Invoke(clientAdapter); } @@ -108,7 +112,11 @@ namespace MQTTnet.Implementations { try { +#if NET45 + var clientSocket = await Task.Factory.FromAsync(_tlsEndpointSocket.BeginAccept, _tlsEndpointSocket.EndAccept, null).ConfigureAwait(false); +#else var clientSocket = await _tlsEndpointSocket.AcceptAsync().ConfigureAwait(false); +#endif var sslStream = new SslStream(new NetworkStream(clientSocket)); await sslStream.AuthenticateAsServerAsync(_tlsCertificate, false, SslProtocols.Tls12, false).ConfigureAwait(false); diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs index e60f641d..d94ddb4e 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttTcpChannel.cs @@ -50,7 +50,11 @@ namespace MQTTnet.Implementations _socket = new Socket(SocketType.Stream, ProtocolType.Tcp); } +#if NET45 + await Task.Factory.FromAsync(_socket.BeginConnect, _socket.EndConnect, _options.Server, _options.GetPort(), null).ConfigureAwait(false); +#else await _socket.ConnectAsync(_options.Server, _options.GetPort()).ConfigureAwait(false); +#endif if (_options.TlsOptions.UseTls) { diff --git a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj index 6e009895..a242439b 100644 --- a/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj +++ b/Frameworks/MQTTnet.NetStandard/MQTTnet.Netstandard.csproj @@ -1,7 +1,7 @@  - netstandard1.3 + netstandard1.3;net45 MQTTnet MQTTnet 2.4.0.0 @@ -22,7 +22,7 @@ - + diff --git a/MQTTnet.sln b/MQTTnet.sln index 8ba4c60b..0afa5ec1 100644 --- a/MQTTnet.sln +++ b/MQTTnet.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 15.0.26730.16 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Core.Tests.csproj", "{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.NetFramework", "Frameworks\MQTTnet.NetFramework\MQTTnet.NetFramework.csproj", "{A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.UniversalWindows", "Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj", "{BD60C727-D8E8-40C3-B8E3-C95A864AE611}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9248C2E1-B9D6-40BF-81EC-86004D7765B4}" @@ -15,8 +13,6 @@ 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("{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}" @@ -62,22 +58,6 @@ Global {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x64.Build.0 = Release|Any CPU {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.ActiveCfg = Release|Any CPU {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.Build.0 = Release|Any CPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Debug|ARM.ActiveCfg = Debug|Any CPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Debug|ARM.Build.0 = Debug|Any CPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Debug|x64.ActiveCfg = Debug|x64 - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Debug|x64.Build.0 = Debug|x64 - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Debug|x86.ActiveCfg = Debug|x86 - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Debug|x86.Build.0 = Debug|x86 - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Release|Any CPU.Build.0 = Release|Any CPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Release|ARM.ActiveCfg = Release|Any CPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Release|ARM.Build.0 = Release|Any CPU - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Release|x64.ActiveCfg = Release|x64 - {A480EF90-0EAA-4D9A-B271-47A9C47F6F7D}.Release|x64.Build.0 = Release|x64 - {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 @@ -110,22 +90,6 @@ Global {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x64.Build.0 = Release|Any CPU {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x86.ActiveCfg = Release|Any CPU {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Release|x86.Build.0 = Release|Any CPU - {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 - {D9D74F33-6943-49B2-B765-7BD589082098}.Debug|ARM.Build.0 = Debug|Any CPU - {D9D74F33-6943-49B2-B765-7BD589082098}.Debug|x64.ActiveCfg = Debug|x64 - {D9D74F33-6943-49B2-B765-7BD589082098}.Debug|x64.Build.0 = Debug|x64 - {D9D74F33-6943-49B2-B765-7BD589082098}.Debug|x86.ActiveCfg = Debug|x86 - {D9D74F33-6943-49B2-B765-7BD589082098}.Debug|x86.Build.0 = Debug|x86 - {D9D74F33-6943-49B2-B765-7BD589082098}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D9D74F33-6943-49B2-B765-7BD589082098}.Release|Any CPU.Build.0 = Release|Any CPU - {D9D74F33-6943-49B2-B765-7BD589082098}.Release|ARM.ActiveCfg = Release|Any CPU - {D9D74F33-6943-49B2-B765-7BD589082098}.Release|ARM.Build.0 = Release|Any CPU - {D9D74F33-6943-49B2-B765-7BD589082098}.Release|x64.ActiveCfg = Release|x64 - {D9D74F33-6943-49B2-B765-7BD589082098}.Release|x64.Build.0 = Release|x64 - {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 @@ -186,9 +150,7 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {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} - {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} {3D283AAD-AAA8-4339-8394-52F80B6304DB} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} diff --git a/Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj b/Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj index 5871b1e8..867b0132 100644 --- a/Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj +++ b/Tests/MQTTnet.TestApp.NetCore/MQTTnet.TestApp.NetCore.csproj @@ -3,7 +3,7 @@ Exe Full - netcoreapp2.0 + netcoreapp2.0;net45 diff --git a/Tests/MQTTnet.TestApp.NetFramework/PerformanceTest.cs b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs similarity index 99% rename from Tests/MQTTnet.TestApp.NetFramework/PerformanceTest.cs rename to Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs index 9f44419e..d7060f20 100644 --- a/Tests/MQTTnet.TestApp.NetFramework/PerformanceTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/PerformanceTest.cs @@ -11,7 +11,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -namespace MQTTnet.TestApp.NetFramework +namespace MQTTnet.TestApp.NetCore { public static class PerformanceTest { diff --git a/Tests/MQTTnet.TestApp.NetCore/Program.cs b/Tests/MQTTnet.TestApp.NetCore/Program.cs index e89c42a0..9519f430 100644 --- a/Tests/MQTTnet.TestApp.NetCore/Program.cs +++ b/Tests/MQTTnet.TestApp.NetCore/Program.cs @@ -19,6 +19,7 @@ namespace MQTTnet.TestApp.NetCore Console.WriteLine("MQTTnet - TestApp.NetFramework"); Console.WriteLine("1 = Start client"); Console.WriteLine("2 = Start server"); + Console.WriteLine("3 = Start performance test"); var pressedKey = Console.ReadKey(true); if (pressedKey.Key == ConsoleKey.D1) { @@ -30,6 +31,11 @@ namespace MQTTnet.TestApp.NetCore Task.Run(() => RunServerAsync(args)); Thread.Sleep(Timeout.Infinite); } + else if (pressedKey.Key == ConsoleKey.D3) + { + Task.Run(PerformanceTest.RunAsync); + Thread.Sleep(Timeout.Infinite); + } } private static async Task RunClientAsync(string[] arguments) diff --git a/Tests/MQTTnet.TestApp.NetFramework/App.config b/Tests/MQTTnet.TestApp.NetFramework/App.config deleted file mode 100644 index 88fa4027..00000000 --- a/Tests/MQTTnet.TestApp.NetFramework/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Tests/MQTTnet.TestApp.NetFramework/MQTTnet.TestApp.NetFramework.csproj b/Tests/MQTTnet.TestApp.NetFramework/MQTTnet.TestApp.NetFramework.csproj deleted file mode 100644 index 7d112f5a..00000000 --- a/Tests/MQTTnet.TestApp.NetFramework/MQTTnet.TestApp.NetFramework.csproj +++ /dev/null @@ -1,103 +0,0 @@ - - - - - Debug - AnyCPU - {D9D74F33-6943-49B2-B765-7BD589082098} - Exe - MQTTnet.TestApp.NetFramework - MQTTnet.TestApp.NetFramework - v4.5.2 - 512 - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - true - bin\x86\Debug\ - DEBUG;TRACE - full - x86 - prompt - MinimumRecommendedRules.ruleset - true - - - bin\x86\Release\ - TRACE - true - pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - true - - - true - bin\x64\Debug\ - DEBUG;TRACE - full - x64 - prompt - MinimumRecommendedRules.ruleset - true - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - true - - - - - - - - - - - - - - - - - - - - - - {a480ef90-0eaa-4d9a-b271-47a9c47f6f7d} - MQTTnet.NetFramework - - - {2ecb99e4-72d0-4c23-99ba-93d511d3967d} - MQTTnet.Core - - - - \ No newline at end of file diff --git a/Tests/MQTTnet.TestApp.NetFramework/Program.cs b/Tests/MQTTnet.TestApp.NetFramework/Program.cs deleted file mode 100644 index 606aafaa..00000000 --- a/Tests/MQTTnet.TestApp.NetFramework/Program.cs +++ /dev/null @@ -1,189 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using MQTTnet.Core; -using MQTTnet.Core.Client; -using MQTTnet.Core.Diagnostics; -using MQTTnet.Core.Packets; -using MQTTnet.Core.Protocol; -using MQTTnet.Core.Server; -using MQTTnet.Implementations; - -namespace MQTTnet.TestApp.NetFramework -{ - public static class Program - { - public static void Main(string[] args) - { - Console.WriteLine("MQTTnet - TestApp.NetFramework"); - Console.WriteLine("1 = Start client"); - Console.WriteLine("2 = Start server"); - Console.WriteLine("3 = Start performance test"); - var pressedKey = Console.ReadKey(true); - if (pressedKey.Key == ConsoleKey.D1) - { - Task.Run(() => RunClientAsync(args)); - Thread.Sleep(Timeout.Infinite); - } - else if (pressedKey.Key == ConsoleKey.D2) - { - Task.Run(() => RunServerAsync(args)); - Thread.Sleep(Timeout.Infinite); - } - else if (pressedKey.Key == ConsoleKey.D3) - { - Task.Run(PerformanceTest.RunAsync); - Thread.Sleep(Timeout.Infinite); - } - } - - private static async Task RunClientAsync(string[] arguments) - { - - MqttNetTrace.TraceMessagePublished += (s, e) => - { - Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}"); - if (e.Exception != null) - { - Console.WriteLine(e.Exception); - } - }; - - try - { - var options = new MqttClientWebSocketOptions - { - Uri = "broker.hivemq.com:8000/mqtt" - }; - - ////var options = new MqttClientOptions - ////{ - //// Server = "localhost", - //// ClientId = "XYZ", - //// CleanSession = true - ////}; - - var mqttClient = new MqttClientFactory().CreateMqttClient(); - mqttClient.ApplicationMessageReceived += (s, e) => - { - Console.WriteLine("### RECEIVED APPLICATION MESSAGE ###"); - Console.WriteLine($"+ Topic = {e.ApplicationMessage.Topic}"); - Console.WriteLine($"+ Payload = {Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}"); - Console.WriteLine($"+ QoS = {e.ApplicationMessage.QualityOfServiceLevel}"); - Console.WriteLine($"+ Retain = {e.ApplicationMessage.Retain}"); - Console.WriteLine(); - }; - - mqttClient.Connected += async (s, e) => - { - Console.WriteLine("### CONNECTED WITH SERVER ###"); - - await mqttClient.SubscribeAsync(new List - { - new TopicFilter("#", MqttQualityOfServiceLevel.AtMostOnce) - }); - }; - - mqttClient.Disconnected += async (s, e) => - { - Console.WriteLine("### DISCONNECTED FROM SERVER ###"); - await Task.Delay(TimeSpan.FromSeconds(5)); - - try - { - await mqttClient.ConnectAsync(options); - } - catch - { - Console.WriteLine("### RECONNECTING FAILED ###"); - } - }; - - try - { - await mqttClient.ConnectAsync(options); - } - catch (Exception exception) - { - Console.WriteLine("### CONNECTING FAILED ###" + Environment.NewLine + exception); - } - - Console.WriteLine("### WAITING FOR APPLICATION MESSAGES ###"); - - var messageFactory = new MqttApplicationMessageFactory(); - while (true) - { - Console.ReadLine(); - - var applicationMessage = messageFactory.CreateApplicationMessage("myTopic", "Hello World", MqttQualityOfServiceLevel.AtLeastOnce); - await mqttClient.PublishAsync(applicationMessage); - } - } - catch (Exception exception) - { - Console.WriteLine(exception); - } - } - - private static async Task RunServerAsync(string[] arguments) - { - MqttNetTrace.TraceMessagePublished += (s, e) => - { - Console.WriteLine($">> [{e.ThreadId}] [{e.Source}] [{e.Level}]: {e.Message}"); - if (e.Exception != null) - { - Console.WriteLine(e.Exception); - } - }; - - try - { - var options = new MqttServerOptions - { - ConnectionValidator = p => - { - if (p.ClientId == "SpecialClient") - { - if (p.Username != "USER" || p.Password != "PASS") - { - return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword; - } - } - - return MqttConnectReturnCode.ConnectionAccepted; - } - }; - - var mqttServer = new MqttServerFactory().CreateMqttServer(options); - await mqttServer.StartAsync(); - - Console.WriteLine("Press any key to exit."); - Console.ReadLine(); - - await mqttServer.StopAsync(); - } - catch (Exception e) - { - Console.WriteLine(e); - } - - Console.ReadLine(); - } - - private static async Task WikiCode() - { - // For .NET Framwork & netstandard apps: - MqttTcpChannel.CustomCertificateValidationCallback = (x509Certificate, x509Chain, sslPolicyErrors, mqttClientTcpOptions) => - { - if (mqttClientTcpOptions.Server == "server_with_revoked_cert") - { - return true; - } - - return false; - }; - } - } -} \ No newline at end of file diff --git a/Tests/MQTTnet.TestApp.NetFramework/Properties/AssemblyInfo.cs b/Tests/MQTTnet.TestApp.NetFramework/Properties/AssemblyInfo.cs deleted file mode 100644 index 5fb54951..00000000 --- a/Tests/MQTTnet.TestApp.NetFramework/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("MQTTnet.TestApp.NetFramework")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Christian Kratky")] -[assembly: AssemblyProduct("MQTTnet")] -[assembly: AssemblyCopyright("Copyright © Christian Kratky 2016-2017")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("7b19b139-2e9d-4f1d-88b4-6180b4cf872a")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file