Replies: 3 comments
-
Almost in your issue title: You created your server, but didn't start it. See line 82 below. MQTTnet/Samples/Server/Server_Simple_Samples.cs Lines 61 to 90 in 6fdee9e Also remember to |
Beta Was this translation helpful? Give feedback.
-
Actually I started it but it doesn't work `
} |
Beta Was this translation helpful? Give feedback.
-
@sefaa-dev You need to call the using MQTTnet;
using MQTTnet.Server;
public class Program
{
static async Task Main(string[] args)
{
var logger = new MQTTnet.Diagnostics.MqttNetEventLogger();
logger.LogMessagePublished += Logger_LogMessagePublished;
var optionBuilder = new MqttServerOptionsBuilder()
.WithDefaultEndpoint()
.WithDefaultEndpointBoundIPAddress(System.Net.IPAddress.Loopback)
.WithDefaultEndpointPort(18883);
var option = optionBuilder.Build();
var factory = new MqttFactory(logger);
using var mqttServer = factory.CreateMqttServer(option);
await mqttServer.StartAsync();
Console.WriteLine("Press Enter to exit.");
Console.ReadLine();
await mqttServer.StopAsync();
}
private static void Logger_LogMessagePublished(object? sender, MQTTnet.Diagnostics.MqttNetLogMessagePublishedEventArgs e)
{
Console.WriteLine(e.LogMessage);
}
}
|
Beta Was this translation helpful? Give feedback.
-
what's my wrong with my code ?
var options = new MqttServerOptionsBuilder(); var mqttFactory = new MqttFactory(); mqttServer = mqttFactory.CreateMqttServer(options.WithDefaultEndpointPort(1800).Build());
C:\Users\DELL_05>netstat -na | find "1800"
C:\Users\DELL_05>
Beta Was this translation helpful? Give feedback.
All reactions