Xamarin mqtt服务器无法访问

时间:2019-02-19 13:44:31

标签: xamarin mqtt

我在Xamarin项目中使用system.Net.mqtt。我创建这样的服务器:

var server = MqttServer.Create();
server.ClientConnected += Debug;
server.ClientDisconnected += Debug;
server.Stopped += (o, e) => Debug($"disconnection ! {e.Message} and {e.Reason} ");

server.Start();

我有一个用micropython编码的nodeMCU。如果我启动并在手机中安装了android MQTT代理,则可以从nodeMCU连接到它,然后推送并订阅消息。完美无瑕。但是,如果我在尝试连接时从nodeMCU获取代理,然后按照上述说明关闭代理并启动服务器,则该请求:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Utils.py", line 10, in __init__
File "Utils.py", line 16, in ConnectMQTT
File "umqtt/simple.py", line 99, in connect
MQTTException: 2

我很确定问题是服务器没有运行..或其他:)

更新1:

我检查了执行程序的来源,我不知道它是什么意思,但是它来自这里(Python代码):

    self.sock.write(premsg, i + 2)
    self.sock.write(msg)
    #print(hex(len(msg)), hexlify(msg, ":"))
    self._send_str(self.client_id)
    if self.lw_topic:
        self._send_str(self.lw_topic)
        self._send_str(self.lw_msg)
    if self.user is not None:
        self._send_str(self.user)
        self._send_str(self.pswd)
    resp = self.sock.read(4)
    assert resp[0] == 0x20 and resp[1] == 0x02
    if resp[3] != 0:
        raise MQTTException(resp[3])   <------- Here!
    return resp[2] & 1

0 个答案:

没有答案