Refactor web socket usage

This commit is contained in:
Christian Kratky
2017-09-18 18:20:36 +02:00
parent b5fc6e3d12
commit 32473af7c2
24 changed files with 116 additions and 86 deletions
@@ -394,7 +394,7 @@ namespace MQTTnet.Core.Tests
public Stream ReceiveStream => _stream;
public Stream RawStream => _stream;
public Stream RawReceiveStream => _stream;
public Stream SendStream => _stream;
@@ -18,12 +18,12 @@ namespace MQTTnet.Core.Tests
public IMqttPacketSerializer PacketSerializer { get; } = new MqttPacketSerializer();
public Task ConnectAsync(MqttClientOptions options, TimeSpan timeout)
public Task ConnectAsync(TimeSpan timeout, MqttClientOptions options)
{
return Task.FromResult(0);
}
public Task DisconnectAsync()
public Task DisconnectAsync(TimeSpan timeout)
{
return Task.FromResult(0);
}
@@ -47,7 +47,7 @@ namespace MQTTnet.Core.Tests
return Task.Run(() => _incomingPackets.Take());
}
public IEnumerable<MqttBasePacket> ReceivePackets( CancellationToken cancellationToken )
public IEnumerable<MqttBasePacket> ReceivePackets(CancellationToken cancellationToken)
{
return _incomingPackets.GetConsumingEnumerable();
}
@@ -113,16 +113,16 @@ namespace MQTTnet.TestApp.NetFramework
.Select(i => CreateMessage())
.ToList();
if (false)
{
//send concurrent (test for raceconditions)
var sendTasks = msgs
.Select(msg => PublishSingleMessage(client, msg, ref msgCount))
.ToList();
////if (false)
////{
//// //send concurrent (test for raceconditions)
//// var sendTasks = msgs
//// .Select(msg => PublishSingleMessage(client, msg, ref msgCount))
//// .ToList();
await Task.WhenAll(sendTasks);
}
else
//// await Task.WhenAll(sendTasks);
////}
////else
{
await client.PublishAsync(msgs);
msgCount += msgs.Count;
@@ -18,7 +18,7 @@
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
<PackageCertificateKeyFile>MQTTnet.TestApp.UniversalWindows_TemporaryKey.pfx</PackageCertificateKeyFile>
<PackageCertificateThumbprint>C5051872F588878B167FB976FDF249518AA2DDF0</PackageCertificateThumbprint>
<PackageCertificateThumbprint>13E377A693C923EE9E88EE84B32A4B9881657362</PackageCertificateThumbprint>
<RuntimeIdentifiers>win10;win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
@@ -24,6 +24,11 @@
<TextBlock>ClientId:</TextBlock>
<TextBox x:Name="ClientId"></TextBox>
<StackPanel Orientation="Horizontal">
<RadioButton x:Name="UseTcp" IsChecked="True">TCP</RadioButton>
<RadioButton x:Name="UseWs" >WS</RadioButton>
</StackPanel>
<CheckBox x:Name="UseTls">Use TLS</CheckBox>
<Button Click="Connect">Connect</Button>
<TextBlock>Trace:</TextBlock>
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using Windows.UI.Core;
using Windows.UI.Xaml;
using MQTTnet.Core.Client;
@@ -40,7 +41,7 @@ namespace MQTTnet.TestApp.UniversalWindows
Password = Password.Text,
ClientId = ClientId.Text,
TlsOptions = { UseTls = UseTls.IsChecked == true },
ConnectionType = MqttConnectionType.Ws
ConnectionType = UseTcp.IsChecked == true ? MqttConnectionType.Tcp : MqttConnectionType.Ws
};
try
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp">
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" IgnorableNamespaces="uap mp uap3">
<Identity Name="4fa21172-9128-4e84-8a6d-74b9acde4d58" Publisher="CN=Christian" Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="4fa21172-9128-4e84-8a6d-74b9acde4d58" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
@@ -24,5 +24,7 @@
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="internetClientServer" />
<Capability Name="privateNetworkClientServer" />
</Capabilities>
</Package>