emqttc是一个Erlang的MQTT客户端,支持MQTTV3.1/V3.1.1协议规范。支持并行连接和连接自动恢复。要求ErlangR17+.
特性:
支持MQTTV3.1/V3.1.1协议
QoS0,QoS1,QoS2发布和订阅
TCP/SSLSocket支持
自动重连
Keepalive和ping/pong
示例:
%% connect to broker{ok, C} = emqttc:start_link([{host, "localhost"}, {client_id, <<"simpleClient">>}]),%% subscribeemqttc:subscribe(C, <<"TopicA">>, qos0),%% publishemqttc:publish(C, <<"TopicA">>, <<"Payload...">>),%% receive messagereceive {publish, Topic, Payload} -> io:format("Message Received from ~s: ~p~n", [Topic, Payload])after 1000 -> io:format("Error: receive timeout!~n")end,%% disconnect from brokeremqttc:disconnect(C).
评论