Mqtt Paho C Library iOS: Occuring connection lost frequently.

120 views
Skip to first unread message

User

unread,
Jan 21, 2016, 12:36:20 PM1/21/16
to MQTT

We are developing an App in which MQTT is one of the communication protocols which is used in between server and mobile phone. I have faced an issue of continuous connection lost with MQTT with public server but not with the same server instance working locally. I am using Paho library for integrating MQTT. 

This is my connection code :

 __weak HomeViewController* weakSelf = self;

        if (_mqttClient == NULL) {    

            status = MQTTAsync_create(&_mqttClient, [@"tcp://ip:port" UTF8String], _mqttClientID.UTF8String, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL);

            if (status != MQTTASYNC_SUCCESS) {

                return;

            }

            status = MQTTAsync_setCallbacks(_mqttClient, (__bridge void*)weakSelf, mqttConnectionLost, mqttMessageArrived, NULL);

            if (status != MQTTASYNC_SUCCESS) {

                mqttDestroy((__bridge void*)weakSelf);

            }

            else

            {

                

            }

            MQTTAsync_connectOptions connOptions = MQTTAsync_connectOptions_initializer;

            connOptions.onSuccess = mqttConnectionSucceeded;

            connOptions.onFailure = mqttConnectionFailed;

            connOptions.keepAliveInterval = 300;

            connOptions.cleansession=0;

            connOptions.connectTimeout = 600;

            connOptions.retryInterval=2;

            connOptions.context = (__bridge void*)weakSelf;

            status = MQTTAsync_connect(_mqttClient, &connOptions);

            if (status != MQTTASYNC_SUCCESS) {

                mqttDestroy((__bridge void*)weakSelf);

                 NSLog(@"connection not success");

            }

            else

            {

                NSLog(@"connection success");

            }


 

I have tried changing the QoS settings in server as well as persistance settings in the library. Even though the same problem remains. 

 

Is this occurring because of the timeout problems with the TCP connection? 


We get connection lost message in corresponding call back function with cause null. 

When connection starts, it will connect to the server. The topic are subscribed and subscription will succeed. We are losing connection after that.

 

(Since other clients connected to public server works fine, we believe that the publis server side working fine)

 

Any help appreciated.

Reply all
Reply to author
Forward
0 new messages