MQTT的Erlang客户端:emqttc

dc4g 9年前

emqttc 是一个 Erlang 的 MQTT 客户端,支持 MQTT V3.1/V3.1.1 协议规范。支持并行连接和连接自动恢复。要求 Erlang R17+.

特性:

  • 支持 MQTT V3.1/V3.1.1 协议

  • QoS0, QoS1, QoS2 发布和订阅

  • TCP/SSL Socket 支持

  • 自动重连

  • Keepalive 和 ping/pong

示例:

%% connect to broker  {ok, C} = emqttc:start_link([{host, "localhost"}, {client_id, <<"simpleClient">>}]),     %% subscribe  emqttc:subscribe(C, <<"TopicA">>, qos0),     %% publish  emqttc:publish(C, <<"TopicA">>, <<"Payload...">>),     %% receive message  receive      {publish, Topic, Payload} ->          io:format("Message Received from ~s: ~p~n", [Topic, Payload])  after      1000 ->          io:format("Error: receive timeout!~n")  end,     %% disconnect from broker  emqttc:disconnect(C).

项目主页:http://www.open-open.com/lib/view/home/1439889401333