Skip to main content

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

My requirement is not for different topic but sending multiple messages sequentially one by one for same topic.

Regards,
Sen

On Tue, Jun 28, 2016 at 9:23 AM, Kenosys Embedded Solutions <kenosysembeddedsolutions@xxxxxxxxx> wrote:
Hi i have not tried publishing multiple topics.  Did you try changing the topic and payload before mqtt_publish.


On Tuesday 28 June 2016 12:04 AM, test check wrote:
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




_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev


_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev


Back to the top