diff --git a/Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketsChannel.cs b/Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketsChannel.cs index da429c7..8d51812 100644 --- a/Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketsChannel.cs +++ b/Frameworks/MQTTnet.NetStandard/Implementations/MqttWebSocketsChannel.cs @@ -10,12 +10,12 @@ namespace MQTTnet.Implementations { public sealed class MqttWebSocketsChannel : IMqttCommunicationChannel, IDisposable { - private ClientWebSocket _webSocket = null; + private ClientWebSocket _webSocket; private const int BufferSize = 4096; private const int BufferAmplifier = 20; - private byte[] WebSocketBuffer = new byte[BufferSize * BufferAmplifier]; - private int WebSocketBufferSize = 0; - private int WebSocketBufferOffset = 0; + private readonly byte[] WebSocketBuffer = new byte[BufferSize * BufferAmplifier]; + private int WebSocketBufferSize; + private int WebSocketBufferOffset; public MqttWebSocketsChannel() { @@ -36,9 +36,6 @@ namespace MQTTnet.Implementations { throw new MqttCommunicationException(exception); } - finally - { - } } public async Task DisconnectAsync() @@ -49,7 +46,9 @@ namespace MQTTnet.Implementations public void Dispose() { if (_webSocket != null) + { _webSocket.Dispose(); + } } public Task ReadAsync(byte[] buffer) @@ -102,9 +101,10 @@ namespace MQTTnet.Implementations public Task WriteAsync(byte[] buffer) { - if (buffer == null) throw new ArgumentNullException(nameof(buffer)); + if (buffer == null) { + throw new ArgumentNullException(nameof(buffer)); + } - var writeBuffer = System.Text.Encoding.ASCII.GetString(buffer); try { return _webSocket.SendAsync(new ArraySegment(buffer), WebSocketMessageType.Binary, true, diff --git a/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs b/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs index 4d25d10..1cd6d6f 100644 --- a/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs +++ b/Frameworks/MQTTnet.NetStandard/MqttClientFactory.cs @@ -11,12 +11,14 @@ namespace MQTTnet { public IMqttClient CreateMqttClient(MqttClientOptions options) { - if (options == null) throw new ArgumentNullException(nameof(options)); + if (options == null) { + throw new ArgumentNullException(nameof(options)); + } return new MqttClient(options, new MqttChannelCommunicationAdapter(GetMqttCommunicationChannel(options), new MqttPacketSerializer())); } - private IMqttCommunicationChannel GetMqttCommunicationChannel(MqttClientOptions options) + private static IMqttCommunicationChannel GetMqttCommunicationChannel(MqttClientOptions options) { switch (options.ConnectionType) { diff --git a/MQTTnet.TestApp.NetCore/Program.cs b/MQTTnet.TestApp.NetCore/Program.cs index df9f9b4..4644471 100644 --- a/MQTTnet.TestApp.NetCore/Program.cs +++ b/MQTTnet.TestApp.NetCore/Program.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace MQTTnet.TestApp.NetCore { - class Program + public static class Program { public static void Main(string[] args) {