Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When the timeout to reconnect, prompts the clientid is connected, return to the state of “ConnectionRefusedIdentiferRejected” #42

Open
shanyulaile opened this issue Feb 29, 2016 · 0 comments

Comments

@shanyulaile
Copy link

When the timeout to reconnect, prompts the clientid is connected, return to the state of “ConnectionRefusedIdentiferRejected”
My code is as follows

self.client = [[MQTTClient alloc] initWithClientId:clientID cleanSession:YES];

[self.client connectToHost:kMQTTServerHost completionHandler:^(MQTTConnectionReturnCode code) { SYLog(@"client is connected with id %@", clientID);

        if (code == ConnectionAccepted) {
            SYLog(@"did connect...");
            // The client is connected when this completion handler is called
            SYLog(@"client is connected with id %@", clientID);
            // Subscribe to the topic
            [weakself.client subscribe:[NSString stringWithFormat:@"%@_%@", kTopic, usercount.enterprise_code] withCompletionHandler:^(NSArray *grantedQos) {
                // The client is effectively subscribed to the topic when this completion handler is called
                SYLog(@"subscribed to topic %@", [NSString stringWithFormat:@"%@_%@", kTopic, usercount.enterprise_code]);
                BOOL res = [weakself.client enableBackgrounding];
                if (!res) {
                    SYLog(@"Failed to enable background socket...");
                }

            }];

        } else {
            SYLog(@"Failed to connect to server...");
        }
    }];

[application setKeepAliveTimeout:600 handler:^{
    SYLog(@"timeout handler activited...");
        [weakself.client reconnect];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant