behrooz bozorg chami
This's my code.
using System;
using System.Threading;
using System.Threading.Tasks;
using MQTTnet.Server;
using MQTTnet;
using System.Text;
using static System.Console;
namespace MqttBroker
{
class Program
{
static void Main(string[] args)
{
var options = new MqttServerOptionsBuilder()
.WithDefaultEndpoint();
var server = new MqttFactory().CreateMqttServer(options.Build());
server.InterceptingPublishAsync += Server_InterceptingPublishAsync;
server.StartAsync();
ReadLine();
Task Server_InterceptingPublishAsync(InterceptingPublishEventArgs arg)
{
var payload = arg.ApplicationMessage?.Payload == null ? null : Encoding.UTF8.GetString(arg.ApplicationMessage?.Payload);
WriteLine(
" TimeStamp: {0} -- Message: ClientId = {1}, Topic = {2}, Payload = {3}, QoS = {4}, Retain-Flag = {5}",
DateTime.Now,
arg.ClientId,
arg.ApplicationMessage?.Topic,
payload,
arg.ApplicationMessage?.QualityOfServiceLevel,
arg.ApplicationMessage?.Retain);
return Task.CompletedTask;
}
}
}
If I did comment out "//await server.StartAsync();" and used server.StartAsync(); it's ok.
So,let me know solution,and also I am waiting for MQTT broker with username/password authenticated from clients request.
Bigberm
Hi,
I got this error when using await in front of // Start the server await server.StartAsync();
"The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'."
How to fix it?
Thank you,
Bigberm