Я построил это ниже и получил эту ошибку < /p>
У меня есть версия MQTTnet 4.1.6.1152. Кто -нибудь может помочь мне решить это? < /P>
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>
и ошибка < /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?)
Подробнее здесь: https://stackoverflow.com/questions/794 ... net-client
У меня есть ошибка под названием «Ошибка параметров в mqttnet.client» ⇐ C#
Место общения программистов C#
1738924606
Anonymous
Я построил это ниже и получил эту ошибку < /p>
У меня есть версия MQTTnet 4.1.6.1152. Кто -нибудь может помочь мне решить это? < /P>
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>
и ошибка < /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?)
Подробнее здесь: [url]https://stackoverflow.com/questions/79420454/i-have-an-error-called-options-error-in-mqttnet-client[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия