我必须创建一个非常基本的Mqtt演示,因此我遵循并下载了这示例。
它工作得很完美,但它是一个带有Net5.0的控制台应用程序。
我必须让它在wpf 4.5.2上工作。解决方案。根据这个,这是可能的。

因此,以上面的解决方案为例

我创建了一个具有相同参考性的项目。

对于每个项目,我还添加了正确的使用语句,如示例中所示。
所以一切都应该是正确的,但是当我粘贴服务器的代码时,我会得到这些错误
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发布于 2022-06-28 13:00:08
MQTT正在迅速成为物联网部署的主要协议之一。
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发布于 2022-09-12 11:17:08
您试图在旧版本3.1.x示例中使用MQTTNet新版本4.0.1.184。
如果您想使用最新的MQTTNet (4.x)版本,那么使用最新的示例。就像他们的github页面上的那个- Samples.cs
MQTTNet (客户端)版本与MQTT (协议)版本无关,而且据了解它们是可互操作的。例如,MQTT 3.1.1可以与MQTTNet 4.x客户端一起使用。
https://stackoverflow.com/questions/72697486
复制相似问题