mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 17:23:04 +08:00
Fix client dead lock and protocol version issues.
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Server;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace MQTTnet.TestApp.NetCore
|
||||
{
|
||||
@@ -38,6 +37,12 @@ namespace MQTTnet.TestApp.NetCore
|
||||
// based payload with the timestamp is a suitable use case.
|
||||
context.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(DateTime.Now.ToString("O"));
|
||||
}
|
||||
|
||||
if (context.ApplicationMessage.Topic == "not_allowed_topic")
|
||||
{
|
||||
context.AcceptPublish = false;
|
||||
context.CloseConnection = true;
|
||||
}
|
||||
},
|
||||
SubscriptionInterceptor = context =>
|
||||
{
|
||||
@@ -72,27 +77,27 @@ namespace MQTTnet.TestApp.NetCore
|
||||
ConsoleColor.Magenta);
|
||||
};
|
||||
|
||||
options.ApplicationMessageInterceptor = c =>
|
||||
{
|
||||
if (c.ApplicationMessage.Payload == null || c.ApplicationMessage.Payload.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//options.ApplicationMessageInterceptor = c =>
|
||||
//{
|
||||
// if (c.ApplicationMessage.Payload == null || c.ApplicationMessage.Payload.Length == 0)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
try
|
||||
{
|
||||
var content = JObject.Parse(Encoding.UTF8.GetString(c.ApplicationMessage.Payload));
|
||||
var timestampProperty = content.Property("timestamp");
|
||||
if (timestampProperty != null && timestampProperty.Value.Type == JTokenType.Null)
|
||||
{
|
||||
timestampProperty.Value = DateTime.Now.ToString("O");
|
||||
c.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(content.ToString());
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
};
|
||||
// try
|
||||
// {
|
||||
// var content = JObject.Parse(Encoding.UTF8.GetString(c.ApplicationMessage.Payload));
|
||||
// var timestampProperty = content.Property("timestamp");
|
||||
// if (timestampProperty != null && timestampProperty.Value.Type == JTokenType.Null)
|
||||
// {
|
||||
// timestampProperty.Value = DateTime.Now.ToString("O");
|
||||
// c.ApplicationMessage.Payload = Encoding.UTF8.GetBytes(content.ToString());
|
||||
// }
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// }
|
||||
//};
|
||||
|
||||
mqttServer.ClientDisconnected += (s, e) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user