问题
Im using system.Net.mqtt in a Xamarin project. I create a server like this:
var server = MqttServer.Create();
server.ClientConnected += Debug;
server.ClientDisconnected += Debug;
server.Stopped += (o, e) => Debug($"disconnection ! {e.Message} and {e.Reason} ");
server.Start();
I have a nodeMCU coded y micropython. If I start and android MQTT broker in the phone I CAN connect to it from the nodeMCU, and push and subscribe to messages. Flawless. But if I switch off the broker and start the server as stated before I get this from the nodeMCU when trying to connect:
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
I'm pretty sure the problem is that the server is not running.. or something :)
UPDATE 1:
I checked where the exection comes from, I have no idea what it means but it comes from here (Python code):
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
来源:https://stackoverflow.com/questions/54767744/xamarin-mqtt-server-unaccessible