Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Paho Mqtt C Client: Automatic reconnect issue when connection is lost.

connectTimeout is the max length of time to be allowed for the connect process to complete: TCP socket connect, MQTT connect and receipt of CONNACK.

keepAlive time is defined by MQTT: to detect whether the TCP connection is still alive after the connect has completed. 

The two settings are independent.  You could try taking a client trace to see if that helps explain what is going on.  Set the environment variables:



MQTT_C_CLIENT_TRACE_LEVEL=PROTOCOL (if you just want MQTT packets, leave this out for the full trace)


On 04/07/2017 06:39, vikas sharma wrote:

I am using Paho Mqtt C Client on my IMX6 device.Providing below some details regarding my code.

MQTTAsync client;
MQTTAsync_connectOptions conn_opts = MQTTAsync_connectOptions_initializer;

Default connection initializer value.
#define MQTTAsync_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 4, 60, 1, 10, NULL, NULL, NULL, 30, 0,\
NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 1, 60}

    conn_opts.keepAliveInterval = 5;
    conn_opts.cleansession = 1;
    conn_opts.automaticReconnect = 1;
    conn_opts._onSuccess_ = onConnect;
    conn_opts._onFailure_ = onConnectFailure;
    conn_opts.context = client;

void onConnect(void* context, MQTTAsync_successData* response)
    printf("Successful connection\n");
    connectionStatus = CONNECTION_OK;

void onConnectFailure(void* context, MQTTAsync_failureData* response)
    printf("Connect failed, rc %d\n", response ? response->code : 0);

1. The issue i am facing with the sdk is that i am not able to see the prints of onConnectFailure callback sometimes.Although it works fine and i can see the logs most of the time.(2 out of 10 times)
Second issue is i am not able to see onConnect callback prints.If onConnectFailure prints are coming sometimes,same shall be the case with onConnect callback.
What is the exact meaning of connectTimeout value in default initializer.What shall be its value if the keepalive timeout is 5 secs.?

paho-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

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

Back to the top