所以以上面的解決方案為例

我用相同的參考創建了自己的專案

對于每個專案,我還添加了正確的 using 陳述句,如示例中所示。
所以一切都應該是正確的,但是當我粘貼服務器的代碼時,我得到了這些錯誤
MqttServerOptionsBuilder options = new MqttServerOptionsBuilder()
.WithDefaultEndpoint()
.WithDefaultEndpointPort(707)
.WithConnectionValidator(OnNewConnection)
.WithApplicationMessageInterceptor(OnNewMessage);
IMqttServer mqttServer = new MqttFactory().CreateMqttServer();

并且對于客戶,我也遇到其他錯誤

問題出在哪里?謝謝
- -添加 - -
按照這里的要求是錯誤
(1) Error CS1061 'IManagedMqttClient' does not contain a definition for 'ConnectedHandler' and no accessible extension method 'ConnectedHandler' accepting a first argument of type 'IManagedMqttClient' could be found (are you missing a using directive or an assembly reference?) Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 43 25 IntelliSense Active
(2) Error CS0246 The type or namespace name 'MqttClientConnectedHandlerDelegate' could not be found (are you missing a using directive or an assembly reference?) Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 43 48 IntelliSense Active
(3) Error CS0103 The name 'OnConnected' does not exist in the current context Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 43 83 IntelliSense Active
(4) Error CS1061 'IManagedMqttClient' does not contain a definition for 'DisconnectedHandler' and no accessible extension method 'DisconnectedHandler' accepting a first argument of type 'IManagedMqttClient' could be found (are you missing a using directive or an assembly reference?) Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 44 25 IntelliSense Active
(5) Error CS0246 The type or namespace name 'MqttClientDisconnectedHandlerDelegate' could not be found (are you missing a using directive or an assembly reference?) Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 44 51 IntelliSense Active
(6) Error CS0103 The name 'OnDisconnected' does not exist in the current context Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 44 89 IntelliSense Active
(7) Error CS1061 'IManagedMqttClient' does not contain a definition for 'ConnectingFailedHandler' and no accessible extension method 'ConnectingFailedHandler' accepting a first argument of type 'IManagedMqttClient' could be found (are you missing a using directive or an assembly reference?) Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 45 25 IntelliSense Active
(8) Error CS0246 The type or namespace name 'ConnectingFailedHandlerDelegate' could not be found (are you missing a using directive or an assembly reference?) Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 45 55 IntelliSense Active
(9) Error CS0103 The name 'OnConnectingFailed' does not exist in the current context Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 45 87 IntelliSense Active
(10) Error CS1061 'IManagedMqttClient' does not contain a definition for 'ApplicationMessageReceivedHandler' and no accessible extension method 'ApplicationMessageReceivedHandler' accepting a first argument of type 'IManagedMqttClient' could be found (are you missing a using directive or an assembly reference?) Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 47 25 IntelliSense Active
(11) Error CS0246 The type or namespace name 'MqttApplicationMessageReceivedHandlerDelegate' could not be found (are you missing a using directive or an assembly reference?) Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 47 65 IntelliSense Active
(12) Error CS1061 'IManagedMqttClient' does not contain a definition for 'PublishAsync' and no accessible extension method 'PublishAsync' accepting a first argument of type 'IManagedMqttClient' could be found (are you missing a using directive or an assembly reference?) Client C:\Development\MqttDemo\MqttDemo\Client\MainWindow.xaml.cs 56 29 IntelliSense Active
uj5u.com熱心網友回復:
MQTT 正迅速成為 IOT(物聯網)部署的主要協議之一。
MQTT 有兩種不同的變體和多個版本。
MQTT v3.1.0 –
MQTT v3.1.1 – 常用
MQTT v5 – 目前受限使用
MQTT-SN – 見后面的注釋
您遵循的示例使用版本3.0.16。MQTT v3.1.1 是常用版本,v3.10 和 3.1.1 差別很小。所以降低你的 MQTT 來解決這個問題。
Install-Package MQTTnet -Version 3.0.16
客戶:
Install-Package MQTTnet.Extensions.ManagedClient -Version 3.0.16
參考:鏈接1 ,鏈接2 ,鏈接3,鏈接4
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/496868.html
上一篇:點擊wpf串列中的專案后彈出內容
下一篇:在TabControl中為TabItems使用ControlTemplate后,TabItems選項卡的方向與TabStripPlacement不匹配
