"No connection could be made because the target machine actively refused it" 连接到 VerneMQ

"No connection could be made because the target machine actively refused it" connecting to VerneMQ

我在 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: 'Exception connecting to the broker'

uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException
HResult=0x80131500 Message=Exception connecting to the broker
Source=M2Mqtt.Net StackTrace: at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password, Boolean willRetain, Byte 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 10 12 MQTT\MQTTSendReceive\MQTTSendReceive\MQTT.cs:line 17 at MQTTSendReceive.Program.Main(String[] args) in C:\Projects 10 12 MQTT\MQTTSendReceive\MQTTSendReceive\Program.cs:line 13

Inner Exception 1: SocketException: No connection could be made because the target machine actively refused it :1883

我看不到我被屏蔽的地方

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

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

allow_anonymous = on

listener.tcp.default = 0.0.0.0:1883