Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Problem with message arrived.

The sprintf call as you have it assumes that the payload is null-terminated.    This is the message arrived callback from the paho_c_sub.c sample:

int messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
{
        if (opts.showtopics)
                printf("%s\t", topicName);
        if (opts.nodelimiter)
                printf("%.*s", message->payloadlen, (char*)message->payload);
        else
                printf("%.*s%c", message->payloadlen, (char*)message->payload, opts.delimiter);
        fflush(stdout);
        MQTTAsync_freeMessage(&message);
        MQTTAsync_free(topicName);
        return 1;
}

Ian


On 14/12/2017 13:28, Vamsinag Gunti wrote:

Hello Ian,

I am printing it to the console using puts() function.

char* payloadptr;
payloadptr = (char*)malloc(message->payloadlen);
sprintf(payloadptr, "%s", ((char*)message->payload));
puts(payloadptr);

How are you displaying the content of the payload? (In code terms)

Ian

--

Best Regards,
Vamsinag Gunti


_______________________________________________
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

-- 
Ian Craggs
icraggs@xxxxxxxxxx                 IBM United Kingdom
Paho Project Lead; Committer on Mosquitto

Back to the top