$SYS/clients/[client-id]/connectedtime
which could be used to get the list of connected clients (using wildcard in the subscription)MqttTcpChannel
constructors have different behavior.mqttClient.UseDisconnectedHandler(async e =>
{
Console.WriteLine("### DISCONNECTED FROM SERVER ###");
await Task.Delay(TimeSpan.FromSeconds(5));
try
{
await mqttClient.ConnectAsync(options, CancellationToken.None); // Since 3.0.5 with CancellationToken
}
catch
{
Console.WriteLine("### RECONNECTING FAILED ###");
}
});
@mrNo0b You can set the following options:
public string ClientId { get; set; } = Guid.NewGuid().ToString("N");
public bool CleanSession { get; set; } = true;
public IMqttClientCredentials Credentials { get; set; }
public IMqttExtendedAuthenticationExchangeHandler ExtendedAuthenticationExchangeHandler { get; set; }
public MqttProtocolVersion ProtocolVersion { get; set; } = MqttProtocolVersion.V311;
public IMqttClientChannelOptions ChannelOptions { get; set; }
public TimeSpan CommunicationTimeout { get; set; } = TimeSpan.FromSeconds(10);
public TimeSpan KeepAlivePeriod { get; set; } = TimeSpan.FromSeconds(15);
public MqttApplicationMessage WillMessage { get; set; }
public uint? WillDelayInterval { get; set; }
public string AuthenticationMethod { get; set; }
public byte[] AuthenticationData { get; set; }
public uint? MaximumPacketSize { get; set; }
public ushort? ReceiveMaximum { get; set; }
public bool? RequestProblemInformation { get; set; }
public bool? RequestResponseInformation { get; set; }
public uint? SessionExpiryInterval { get; set; }
public ushort? TopicAliasMaximum { get; set; }
public List<MqttUserProperty> UserProperties { get; set; }
So, I would say no, that's not possible.
Well, I used this
serverOptions = new MqttServerOptionsBuilder()
.WithDefaultEndpoint()
.WithDefaultEndpointPort(mqttServer.Port)
.WithConnectionValidator(c =>
{
foreach (MqttUser user in mqttServer.Users)
{
if (user.Username == c.Username && user.Password == c.Password)
{
c.ReasonCode = MqttConnectReasonCode.Success;
return;
}
}
c.ReasonCode = MqttConnectReasonCode.BadUserNameOrPassword;
})
.WithSubscriptionInterceptor(c =>
{
c.AcceptSubscription = true;
})
.WithApplicationMessageInterceptor(c =>
{
c.AcceptPublish = true;
})
.Build();
and it seems to work for me...
However I honestly do not know if it is secure in any way, but it is fine for my use case.