• 大小: 74KB
    文件类型: .zip
    金币: 2
    下载: 3 次
    发布日期: 2021-06-09
  • 语言: C/C++
  • 标签: C++  mqtt协议  物联网  

资源简介

C++实现mqtt协议:官网的mqtt c++实现,个觉得写得非常棒!

资源截图

代码片段和文件信息

//async_client.cpp

/*******************************************************************************
 * Copyright (c) 2013 Frank Pagliughi 
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution. 
 *
 * The Eclipse Public License is available at 
 *    http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at 
 *   http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * Contributors:
 *    Frank Pagliughi - initial implementation and documentation
 *******************************************************************************/

#include “mqtt/async_client.h“
#include “mqtt/token.h“
#include “mqtt/message.h“
#include 
#include 
#include 
#include 
#include 

#include 

namespace mqtt {

/////////////////////////////////////////////////////////////////////////////

async_client::async_client(const std::string& serverURI const std::string& clientId)
: serverURI_(serverURI) clientId_(clientId) 
persist_(nullptr) userCallback_(nullptr)
{
MQTTAsync_create(&cli_ const_cast(serverURI.c_str())
 const_cast(clientId.c_str())
 MQTTCLIENT_PERSISTENCE_DEFAULT nullptr);
}


async_client::async_client(const std::string& serverURI const std::string& clientId
   const std::string& persistDir)
: serverURI_(serverURI) clientId_(clientId) 
persist_(nullptr) userCallback_(nullptr)
{
MQTTAsync_create(&cli_ const_cast(serverURI.c_str())
 const_cast(clientId.c_str())
 MQTTCLIENT_PERSISTENCE_DEFAULT 
 const_cast(persistDir.c_str()));
}

async_client::async_client(const std::string& serverURI const std::string& clientId 
   iclient_persistence* persistence)
: serverURI_(serverURI) clientId_(clientId) 
persist_(nullptr) userCallback_(nullptr)
{
if (!persistence) {
MQTTAsync_create(&cli_ const_cast(serverURI.c_str())
 const_cast(clientId.c_str())
 MQTTCLIENT_PERSISTENCE_NONE nullptr);
}
else {
persist_ = new MQTTClient_persistence {
persistence
&iclient_persistence::persistence_open
&iclient_persistence::persistence_close
&iclient_persistence::persistence_put
&iclient_persistence::persistence_get
&iclient_persistence::persistence_remove
&iclient_persistence::persistence_keys
&iclient_persistence::persistence_clear
&iclient_persistence::persistence_containskey
};

MQTTAsync_create(&cli_ const_cast(serverURI.c_str())
 const_cast(clientId.c_str())
 MQTTCLIENT_PERSISTENCE_USER persist_);
}
}

async_client::~async_client()
{
MQTTAsync_destroy(&cli_);
delete persist_;
}

// --------------------------------------------------------------------------

void async_client

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\
     文件        1853  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\CONTRIBUTING.md
     文件        2935  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\Makefile
     文件         873  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\README.md
     文件        1605  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\about.html
     目录           0  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\doc\
     文件           0  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\doc\.include
     文件       75583  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\doc\Doxyfile
     文件        1564  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\edl-v10
     文件       11232  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\epl-v10
     文件        9230  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\notice.html
     目录           0  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\
     文件       17688  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\async_client.cpp
     文件        4088  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\client.cpp
     文件        6327  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\iclient_persistence.cpp
     文件        2972  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\message.cpp
     目录           0  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\
     文件       18963  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\async_client.h
     文件        2173  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\callback.h
     文件        6689  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\client.h
     文件        5354  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\connect_options.h
     文件        3114  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\delivery_token.h
     文件        3165  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\exception.h
     文件        2586  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\iaction_listener.h
     文件        4473  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\iclient_persistence.h
     文件        4559  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\ipersistable.h
     文件        5049  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\message.h
     文件        9387  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\token.h
     文件        3032  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\mqtt\topic.h
     目录           0  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\obj\
     文件           0  2014-04-04 08:43  org.eclipse.paho.mqtt.cpp-55216695b73dc7ab2a9f917878de2b8eddb7c474\src\obj\async_client.dep
............此处省略12个文件信息

评论

共有 条评论