1

我在 Azure Ubuntu 16.04 VM 上安装了 VerneMQ,并打开了入站和出站端口 1883。VerneMQ 配置为侦听端口 1883,已启用匿名连接,并且已启动 vernemq(vernemq start)。

allow_anonymous = on

listener.tcp.default = 127.0.0.1:1883

我在我的 Windows 10 PC 上创建了一个 C# 控制台应用程序,用于将消息发送到 VM 上的 MQTT 代理。我正在使用 NuGet 包 M2Mqtt 4.3.0 版,并在我的 Windows 10 防火墙中打开了入站和出站 1883。

string broker = "<ip address>";
MqttClient client = new MqttClient(broker);
byte code = client.Connect(Guid.NewGuid().ToString());

当我尝试连接时,我收到连接被拒绝的错误消息。

uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException: '异常连接到代理'

uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException
HResult=0x80131500 消息=连接到代理的异常
源=M2Mqtt.Net StackTrace:在 uPLibrary.Networking.M2Mqtt.MqttClient.Connect(字符串 clientId,字符串用户名,字符串密码,布尔 willRetain,字节willQosLevel, Boolean willFlag, String willTopic, String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod) at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId) at MQTTSendReceive.MQTT.SendMQTTMessage() in C:\Projects\19 10 12 MQTT\ MQTTSendReceive\MQTTSendReceive\MQTT.cs:第 17 行,位于 C:\Projects\19 中的 MQTTSendReceive.Program.Main(String[] args) 10 12 MQTT\MQTTSendReceive\MQTTSendReceive\Program.cs:第 13 行

内部异常1:SocketException:无法建立连接,因为目标机器主动拒绝它:1883

我看不到我被封锁的地方。

4

1 回答 1

3

您已经告诉 VerneMQ 在 localhost (127.0.0.1) 上进行侦听,这意味着您只能从 Ubuntu 机器连接到它。

如果您希望能够从其他地方访问它,您需要告诉它监听所有接口(0.0.0.0)

allow_anonymous = on

listener.tcp.default = 0.0.0.0:1883
于 2018-10-14T16:15:41.223 回答