Not able to connect with broker using MQTTNet library .net core

I need an help, I can't connect with the broker. I'm using MQTTNet library into my api project .net core this is my code:

// GET: api/<SendCommandController>
public void Get()

    var options = new MqttClientOptionsBuilder()
    .WithTcpServer("", 1883)

    var factory = new MqttFactory();
    var mqttClient = factory.CreateMqttClient();

    mqttClient.ConnectAsync(options, CancellationToken.None);

    var message = new MqttApplicationMessageBuilder()
    .WithPayload("Hello World")

    mqttClient.PublishAsync(message, CancellationToken.None); 

so I follow the tutorial but can't connect to broker hivemq and I can't connect to my personal broker. So, I tested hivemq broker with mqtt.fx and works. Only in the code the return is connected = false.

Any ideas? the error is "the client is not connected"

enter image description here

Read more here:

Content Attribution

This content was originally published by Mr. Developer at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: