curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

RE: MQTT sub times out

From: Matthew Bobowski via curl-library <curl-library_at_lists.haxx.se>
Date: Tue, 25 Oct 2022 07:28:27 +0000

How is libcurl supposed to know when MQTT data is finished? It is a REST library and typically the connection is not maintained. MQTT is 180 degrees apart from a REST library, and it persists the connection. I’m not sure why you would even use libcurl to do this. Instead, just use an MQTT library (i.e. Paho).


-MJB

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: Hamza Farooq via curl-library<mailto:curl-library_at_lists.haxx.se>
Sent: Tuesday, October 25, 2022 3:23 AM
To: Henrik Holst<mailto:henrik.holst_at_millistream.com>
Cc: Hamza Farooq<mailto:hamzahfrq.sub_at_gmail.com>; libcurl development<mailto:curl-library_at_lists.haxx.se>
Subject: Re: MQTT sub times out

Hello,

Good hint, thanks! In my case, size is 1, nmemb is 34 so changing it
to "return nmemb * size" does not make a difference. Do you have any
other idea what the issue might be?
Thanks for your help!


Hamza

On Mon, Oct 24, 2022 at 10:48 PM Henrik Holst
<henrik.holst_at_millistream.com> wrote:
>
> Hi,
>
> this happens because you do return nmemb; in write_data() instead of return nmemb*size; since that is the actual data size in bytes, so curl_easy_perform is waiting for you to consume all data and thus hangs since you never do (or rather don't tell curl that you do).
>
> /HH
>
> Den mån 24 okt. 2022 kl 22:40 skrev Hamza Farooq via curl-library <curl-library_at_lists.haxx.se>:
>>
>> Hello,
>>
>> I am using libcurl for receiving mqtt data (subscribe) with following
>> configuration:
>>
>> curl_easy_setopt( g_curl, CURLOPT_VERBOSE, 0 ); /* set verbosity */
>> curl_easy_setopt( g_curl, CURLOPT_URL, buf ); /* Set the URL/path */
>> curl_easy_setopt( g_curl, CURLOPT_PORT, g_port ); /* Set the port */
>> curl_easy_setopt( g_curl, CURLOPT_DEFAULT_PROTOCOL, "mqtt"); /* if URL
>> misses scheme */
>> curl_easy_setopt( g_curl, CURLOPT_NOPROGRESS, 1); /* turn off progress meter */
>> curl_easy_setopt( g_curl, CURLOPT_TIMEOUT, 30); /* connection timeout */
>> curl_easy_setopt( g_curl, CURLOPT_WRITEFUNCTION, write_data);
>> curl_easy_setopt( g_curl, CURLOPT_WRITEDATA, user_data);
>>
>> cc = curl_easy_perform(g_curl);
>> curl_easy_cleanup(g_curl);
>> if (cc != CURLE_OK) {
>> fprintf( stderr, "could not get MQTT data (%d)\n",
>> cc );
>> return sz;
>> }
>>
>> Here is what my write_data() looks like:
>>
>> size_t write_data(char *in_data, size_t size, size_t nmemb, void *user_data){
>>
>> fprintf( stdout, "entered write_data\n");
>> fprintf( stdout, "Received msg: %s\n", in_data+2);
>>
>> //perform data operations
>> return nmemb;
>> }
>>
>> Problem:
>> I receive the data in my write_data function, but the
>> curl_easy_perform() call in the main function does not return. It only
>> returns after the timeout is over, regardless of how many times the
>> data is published by the MQTT broker and received by the app. Is this
>> expected behavior? How can I make curl_easy_perform return?
>>
>> PS: If there is any sample code for libcurl that uses MQTT, please
>> point me in that direction.
>>
>> Best regards,
>> Hamza
>> --
>> Unsubscribe: https://lists.haxx.se/listinfo/curl-library
>> Etiquette: https://curl.se/mail/etiquette.html
--
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html


-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2022-10-25