Ich habe einen Fehler namens "Optionsfehler in mqttnet.client"C#

Ein Treffpunkt für C#-Programmierer
Guest
 Ich habe einen Fehler namens "Optionsfehler in mqttnet.client"

Post by Guest »

Ich habe dies unten erstellt und diesen Fehler erhalten < /p>
Ich habe MQTTNET -Version 4.1.6.1152. Kann mir jemand helfen, dies zu lösen? < /P>

Code: Select all

using System;
using System.Text;
using System.Threading.Tasks;
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Client.Options;
using MQTTnet.Client.Subscribing;

namespace OTtoIT
{
class Program
{
static async Task Main(string[] args)
{
string brokerAddress = "0.0.0.0";  // Your MQTT broker IP address
int brokerPort = 1883;  // Default MQTT port
string topic = "#";  // Your MQTT topic

// Create a new MQTT client
var mqttClient = new MqttFactory().CreateMqttClient();

// Create client options using the MqttClientOptionsBuilder
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithClientId("YourClientId")
.WithTcpServer(brokerAddress, brokerPort)
.WithCleanSession()
.Build();

// Set up the handler for receiving messages
mqttClient.ApplicationMessageReceivedAsync += e =>
{
var payload = Encoding.UTF8.GetString(e.ApplicationMessage.PayloadSegment.ToArray());
Console.WriteLine($"Received message: {payload}");
return Task.CompletedTask;
};

// Connect to the MQTT broker
await mqttClient.ConnectAsync(mqttClientOptions);
Console.WriteLine("Connected to the broker.");

// Subscribe to the topic
var subscribeOptions = new MqttClientSubscribeOptionsBuilder()
.WithTopicFilter(f => { f.WithTopic(topic); })
.Build();

await mqttClient.SubscribeAsync(subscribeOptions);
Console.WriteLine($"Subscribed to topic: {topic}");

// Keep the application running to receive messages
Console.WriteLine("Press any key to exit...");
Console.ReadKey();

// Disconnect the client
await mqttClient.DisconnectAsync();
Console.WriteLine("Disconnected from the broker.");
}
}
}
< /code>
Und der Fehler ist < /p>
The type or namespace name 'Options' does not exist in the namespace 'MQTTnet.Client' (are you missing an assembly reference?)
The type or namespace name 'Subscribing' does not exist in the namespace 'MQTTnet.Client' (are you missing an assembly reference?)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post