mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-21 04:03:05 +08:00
Add Wiki Code.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MQTTnet.Client;
|
using MQTTnet.Client;
|
||||||
@@ -81,7 +83,7 @@ namespace MQTTnet.TestApp.NetCore
|
|||||||
{
|
{
|
||||||
Task.Run(PerformanceTest.RunQoS0Test);
|
Task.Run(PerformanceTest.RunQoS0Test);
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.Sleep(Timeout.Infinite);
|
Thread.Sleep(Timeout.Infinite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,4 +120,22 @@ namespace MQTTnet.TestApp.NetCore
|
|||||||
return Task.FromResult(retainedMessages);
|
return Task.FromResult(retainedMessages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class WikiCode
|
||||||
|
{
|
||||||
|
public void Code()
|
||||||
|
{
|
||||||
|
//Validate certificate.
|
||||||
|
var options = new MqttClientOptionsBuilder()
|
||||||
|
.WithTls(new MqttClientOptionsBuilderTlsParameters
|
||||||
|
{
|
||||||
|
CertificateValidationCallback = (X509Certificate x, X509Chain y, SslPolicyErrors z, IMqttClientOptions o) =>
|
||||||
|
{
|
||||||
|
// TODO: Check conditions of certificate by using above parameters.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Net.Security;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Windows.Security.Cryptography.Certificates;
|
using Windows.Security.Cryptography.Certificates;
|
||||||
@@ -595,7 +597,7 @@ namespace MQTTnet.TestApp.UniversalWindows
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
{
|
{
|
||||||
var options = new MqttServerOptions();
|
var options = new MqttServerOptions();
|
||||||
@@ -714,6 +716,25 @@ namespace MQTTnet.TestApp.UniversalWindows
|
|||||||
var mqttServer = new MqttFactory().CreateMqttServer();
|
var mqttServer = new MqttFactory().CreateMqttServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Setup subscription interceptor.
|
||||||
|
var options = new MqttServerOptionsBuilder()
|
||||||
|
.WithSubscriptionInterceptor(context =>
|
||||||
|
{
|
||||||
|
if (context.TopicFilter.Topic.StartsWith("admin/foo/bar") && context.ClientId != "theAdmin")
|
||||||
|
{
|
||||||
|
context.AcceptSubscription = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.TopicFilter.Topic.StartsWith("the/secret/stuff") && context.ClientId != "Imperator")
|
||||||
|
{
|
||||||
|
context.AcceptSubscription = false;
|
||||||
|
context.CloseConnection = true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Setup and start a managed MQTT client.
|
// Setup and start a managed MQTT client.
|
||||||
var options = new ManagedMqttClientOptionsBuilder()
|
var options = new ManagedMqttClientOptionsBuilder()
|
||||||
|
|||||||
Reference in New Issue
Block a user