Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Multiple messages for C client

Hi,

The query is related to sending multiple messages using the MQTT C client. I have been able to send create my C++ MQTT library by wrapping up the C library. But the example shows only sending one payload message.

My use case is like whenever there is a request for message to be sent, the client who is already connected should take up that message and send it. Basically like waiting for messages on a queue.

Can you please provide some sample?
Following is a small code snippet where I tried to send multiple messages (apologies for

if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)

{

printf("Failed to connect, return code %d\n", rc);

exit(-1);

}

printf("Topic - %s \nClientID: %s\n", TOPIC, CLIENTID);

pubmsg.qos = QOS;

pubmsg.retained = 0;

deliveredtoken = 0;

int count = 0;

while (count != messageCnt)

{

count++;

std::string message = "Telemetry Data #MSG_";

std::ostringstream outputString;

outputString << count;

message += outputString.str();

pubmsg.payload = malloc(message.size() + 1);

strcpy_s((char *)pubmsg.payload, message.size() + 1, message.c_str());

//cout << "Peer: " << (char*)pubmsg.payload << endl;

pubmsg.payloadlen = message.length();

if (count == 26)

{

printf("\n Manual intervention \n");

system("pause");

}

MQTTClient_publishMessage(client, TOPIC, &pubmsg, &token);

std::thread::id mainthdID = std::this_thread::get_id();

printf("\n MSG TOKEN :: %d \n MSG PUBLISHED :: %s\n\n\n", token, pubmsg.payload);

free(pubmsg.payload);

}

while (deliveredtoken != token)

{

// Run until the delivery token is received

// We should have a timeout for this to ensure waiting infinitely for a response

};

Another question



Back to the top