Browse Source

Refactor code

release/3.x.x
Christian Kratky 7 years ago
parent
commit
305578e7e6
4 changed files with 9 additions and 18 deletions
  1. +1
    -1
      Frameworks/MQTTnet.UniversalWindows/Implementations/MqttTcpChannel.cs
  2. +2
    -1
      Frameworks/MQTTnet.UniversalWindows/Implementations/MqttWebSocketChannel.cs
  3. +4
    -7
      Frameworks/MQTTnet.UniversalWindows/Implementations/WebSocketStream.cs
  4. +2
    -9
      Tests/MQTTnet.TestApp.NetFramework/Program.cs

+ 1
- 1
Frameworks/MQTTnet.UniversalWindows/Implementations/MqttTcpChannel.cs View File

@@ -54,8 +54,8 @@ namespace MQTTnet.Implementations
await _socket.ConnectAsync(new HostName(options.Server), options.GetPort().ToString(), SocketProtectionLevel.Tls12); await _socket.ConnectAsync(new HostName(options.Server), options.GetPort().ToString(), SocketProtectionLevel.Tls12);
} }


ReceiveStream = _socket.InputStream.AsStreamForRead();
SendStream = _socket.OutputStream.AsStreamForWrite(); SendStream = _socket.OutputStream.AsStreamForWrite();
ReceiveStream = _socket.InputStream.AsStreamForRead();
RawReceiveStream = ReceiveStream; RawReceiveStream = ReceiveStream;
} }




+ 2
- 1
Frameworks/MQTTnet.UniversalWindows/Implementations/MqttWebSocketChannel.cs View File

@@ -28,10 +28,11 @@ namespace MQTTnet.Implementations
{ {
uri += ":" + options.Port; uri += ":" + options.Port;
} }
_webSocket = new ClientWebSocket(); _webSocket = new ClientWebSocket();
_webSocket.Options.KeepAliveInterval = options.KeepAlivePeriod; _webSocket.Options.KeepAliveInterval = options.KeepAlivePeriod;
await _webSocket.ConnectAsync(new Uri(uri), CancellationToken.None).ConfigureAwait(false); await _webSocket.ConnectAsync(new Uri(uri), CancellationToken.None).ConfigureAwait(false);

RawReceiveStream = new WebSocketStream(_webSocket); RawReceiveStream = new WebSocketStream(_webSocket);
} }




+ 4
- 7
Frameworks/MQTTnet.UniversalWindows/Implementations/WebSocketStream.cs View File

@@ -27,7 +27,7 @@ namespace MQTTnet.Implementations
{ {
var response = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer, currentOffset, count), cancellationToken).ConfigureAwait(false); var response = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer, currentOffset, count), cancellationToken).ConfigureAwait(false);
currentOffset += response.Count; currentOffset += response.Count;
if (response.MessageType == WebSocketMessageType.Close) if (response.MessageType == WebSocketMessageType.Close)
{ {
await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, cancellationToken).ConfigureAwait(false); await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, cancellationToken).ConfigureAwait(false);
@@ -56,15 +56,12 @@ namespace MQTTnet.Implementations
public override bool CanSeek => false; public override bool CanSeek => false;
public override bool CanWrite => true; public override bool CanWrite => true;


public override long Length
{
get { throw new NotSupportedException(); }
}
public override long Length => throw new NotSupportedException();


public override long Position public override long Position
{ {
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
get => throw new NotSupportedException();
set => throw new NotSupportedException();
} }


public override long Seek(long offset, SeekOrigin origin) public override long Seek(long offset, SeekOrigin origin)


+ 2
- 9
Tests/MQTTnet.TestApp.NetFramework/Program.cs View File

@@ -78,8 +78,6 @@ namespace MQTTnet.TestApp.NetFramework
{ {
new TopicFilter("#", MqttQualityOfServiceLevel.AtMostOnce) new TopicFilter("#", MqttQualityOfServiceLevel.AtMostOnce)
}); });

Console.WriteLine("### SUBSCRIBED ###");
}; };


client.Disconnected += async (s, e) => client.Disconnected += async (s, e) =>
@@ -108,17 +106,12 @@ namespace MQTTnet.TestApp.NetFramework


Console.WriteLine("### WAITING FOR APPLICATION MESSAGES ###"); Console.WriteLine("### WAITING FOR APPLICATION MESSAGES ###");


var messageFactory = new MqttApplicationMessageFactory();
while (true) while (true)
{ {
Console.ReadLine(); Console.ReadLine();


var applicationMessage = new MqttApplicationMessage(
"A/B/C",
Encoding.UTF8.GetBytes("Hello World"),
MqttQualityOfServiceLevel.AtLeastOnce,
false
);

var applicationMessage = messageFactory.CreateApplicationMessage("myTopic", "Hello World", MqttQualityOfServiceLevel.AtLeastOnce);
await client.PublishAsync(applicationMessage); await client.PublishAsync(applicationMessage);
} }
} }


Loading…
Cancel
Save