我在1883端口的虚拟机上安装了mosquitto broker。这个虚拟机托管在azure cloud上。为了获得对这个代理的访问,我通过添加入站规则打开了端口。但是我无法从外部发布到这个mosquitto代理网络。
我通过允许端口1883允许来自外部网络的访问来添加入站规则
string ClientId = new Guid().ToString();
client = new MqttClient("104.211.219.200", 1883, false, null);
client.Connect(ClientId);
client.Publish("local", Encoding.UTF8.GetBytes("Message from local PC"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
根据您的描述,根据我的经验,我认为您的mosquitto现在不起作用是由于您的VM网络接口没有添加NSG规则以允许来自端口1883的入站请求。
以下是我在Azure Windows VM上安装mosquitto服务器的步骤。希望能帮助到你。
Just-in-time access
中启用Configuration
功能,然后下载RDP文件以访问此VM。
VCRUNTIME140.dll
的问题,然后安装VC ++ 2015发行版安装(它来自https://www.microsoft.com/en-us/download/details.aspx?id=48145)来修复它。Windows Firewall with Advanced Security
。它允许来自Windows 18上的端口1883的请求。 MQTT.fx
(它来自https://www.hivemq.com/blog/seven-best-mqtt-client-tools/)来测试连接,发布和订阅测试消息。