[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[paho-dev] C++ client crash during connect
|
Hi, I have downloaded the paho-mqtt-c and paho-mqtt-cpp sources from github and I have compiled them.
This is my test code (I got it from the eclipse page):
#include "mqtt/client.h"
int main(int argc, char *argv[])
{
const std::string TOPIC { "hello" };
const std::string PAYLOAD1 { "Hello World!" };
const char* PAYLOAD2 = "Hi there!";
mqtt::client client("tcp://localhost:1883", "TestClient");
mqtt::connect_options connectOptions;
connectOptions.set_keep_alive_interval(20);
connectOptions.set_clean_session(true);
try
{
client.connect(connectOptions);
const mqtt::message_ptr& message = mqtt::make_message(TOPIC, PAYLOAD1);
// message->set_qos(3);
client.publish(message);
client.publish(TOPIC, PAYLOAD2, strlen(PAYLOAD2), 0, false);
client.disconnect();
}
catch (const mqtt::exception& e)
{
qDebug() << "Error: " << e.what() << " [" << e.get_reason_code() << "]";
return 1;
}
return 0;
}
It crashes inside the client.connect(), in particular in file MQTTAsync.c(line 1815) in function MQTTAsync_processCommand() here:
if (command->client->c->connect_state == NOT_IN_PROGRESS)
rc = SOCKET_ERROR;
because command->client->c is null.
Any suggestions? Thank you