c# - Mqtt No such host is known error -
i developing mqtt protocol based application in .net core application develop application using below link mqtt
my code
public static void main(string[] args) { mqttclient client = new mqttclient("broker.hivemq.com"); byte code = client.connect(guid.newguid().tostring(), "username", "password"); console.writeline("code " + code); client.mqttmsgpublished += client_mqttmsgpublished; ushort msgid = client.publish("mytopic", // topic encoding.utf8.getbytes("hai sample chat application"), // message body mqttmsgbase.qos_level_exactly_once, // qos level true); // retained console.writeline("msgid " + msgid); client.mqttmsgpublishreceived += client_mqttmsgpublishreceived; void client_mqttmsgpublished(object sender, mqttmsgpublishedeventargs e) { debug.writeline("messageid = " + e.messageid + " published = " + e.ispublished); console.writeline("messageid = " + e.messageid + " published = " + e.ispublished); } void client_mqttmsgsubscribed(object sender, mqttmsgsubscribedeventargs e) { debug.writeline("subscribed id = " + e.messageid); console.writeline("subscribed id = " + e.messageid); } void client_mqttmsgpublishreceived(object sender, mqttmsgpublisheventargs e) { debug.writeline("received = " + encoding.utf8.getstring(e.message) + " on topic " + e.topic); console.writeline("received = " + encoding.utf8.getstring(e.message) + " on topic " + e.topic); }
}
subscriber code:
mosquitto_sub -h broker.hivemq.com -t mytopic(terminal)
when run application message send subscriber when trying publish message terminal application doesn't receive message
published code in terminal
mosquitto_pub -h broker.hivemq.com -t mytopic -m "hai sample"
so how receive published message terminal?
i using mqtt client mqttclient client = new mqttclient("broker.hivemq.com");
when trying change ip address didn't run getting error like
unhandled exception: system.aggregateexception: 1 or more errors occurred. (no such host known) ---> system.net.sockets.socketexception: no such host known
working fine below code
string[] topic = { "mytopic"}; byte[] qoslevels = { mqttmsgbase.qos_level_exactly_once }; client.subscribe(topic, qoslevels);
the above code missing in code.terminal c# console , c# console terminal.
Comments
Post a Comment