A connection attempt is already running

Post here your questions about the Objective-C API for SFS2X

Moderators: Lapo, Bax

User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 22 Oct 2012, 13:19

Before you disconnect, you can set reconnectionSeconds to zero. This will tell the client basically not to attempt reconnecting.

Code: Select all

[sfsClient setReconnectionSeconds:(NSInteger)];

WHen the client comes back into the foreground, reset that value to something greater than zero to handle network issues when you want the client to be able to reconnect.
A51 Integrated
http://a51integrated.com / +1 416-703-2300
jianchic
Posts: 25
Joined: 08 Apr 2012, 16:38

Re: A connection attempt is already running

Postby jianchic » 22 Oct 2012, 13:46

i'm sorry to say that! that's not work for me either.


Code: Select all

[self setSfs:[SmartFox2XClient smartFoxWithDebugMode:NO delegate:self]];
[self.sfs setReconnectSeconds:0];



- (void)handleApplicationNotification:(NSNotification *)notification {
    NSString *name = [notification name];
    if ([name isEqualToString:UIApplicationDidBecomeActiveNotification]) {
        [self.sfs connect:socket_ip port:9933];
    } else {
        [self.sfs disconnect];
    }
}
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 22 Oct 2012, 13:55

With that code it looks like any other event thrown by the app will cause a disconnection. Instead of using "else" use "else if" and make sure you want to disconnect.

There must be some issues with your code logic if there are multiple attempts to connect to the server. If you're getting "A connection attempt is already running" something has requested a connection attempt - whether that be manual or automatic.
A51 Integrated

http://a51integrated.com / +1 416-703-2300
jianchic
Posts: 25
Joined: 08 Apr 2012, 16:38

Re: A connection attempt is already running

Postby jianchic » 22 Oct 2012, 14:15

Code: Select all

[self setSfs:[SmartFox2XClient smartFoxWithDebugMode:NO delegate:self]];
[self.sfs setReconnectSeconds:0];



- (void)handleApplicationNotification:(NSNotification *)notification {
    NSString *name = [notification name];
    if ([name isEqualToString:UIApplicationDidBecomeActiveNotification]) {
        [self.sfs connect:socket_ip port:9933];
    } else  if ([name isEqualToString:UIApplicationWillResignActiveNotification]){
        [self.sfs disconnect];
    }
}


i change it to this,but there is no change.....T-T
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 22 Oct 2012, 14:25

I think you're chasing your tail here. You need to identify why and when you are loosing a connection and respond appropriately to that scenario. Use trace statement to figure out precisely whats happening with your app. Again, if you're getting "A connection attempt is already running" something is trying to connect. You'll need to figure out where that happens.

This should be

Code: Select all

    if ([name isEqualToString:UIApplicationDidBecomeActiveNotification]) {
        [self.sfs setReconnectSeconds:1]; //or some other custom value so legitimate network issues are resolved automatically
        [self.sfs connect:socket_ip port:9933];
    } else  if ([name isEqualToString:UIApplicationWillResignActiveNotification]){
        [self.sfs setReconnectSeconds:0];
        [self.sfs disconnect];
    }
A51 Integrated

http://a51integrated.com / +1 416-703-2300
jianchic
Posts: 25
Joined: 08 Apr 2012, 16:38

Re: A connection attempt is already running

Postby jianchic » 22 Oct 2012, 15:44

this is always happened when the network environment is not so well
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 22 Oct 2012, 15:54

Well, SFS is designed to try and stay connected. You're trying to handle two situations at the same time. Try focusing on one at a time. Connection lost is unintended. The app going into the background is intentional. Depending on your application, I'm assuming you'd like the client to stay connected. If they keep dropping that connection, SFS will try and reconnect them to the state where they dropped off. If you want to disconnect them on purpose, you have that option. But an connection dropped because of poor network conditions is supposed to be handled by SFS automatically.

You can also play with the User Reconnection Timeframe value in the admin (Zone configuration). Still, tackle one scenario at a time.
A51 Integrated

http://a51integrated.com / +1 416-703-2300
jianchic
Posts: 25
Joined: 08 Apr 2012, 16:38

Re: A connection attempt is already running

Postby jianchic » 22 Oct 2012, 15:58

i think i know when it happened, i disconnect sfs when it is connecting to server,and then i call [connecttoserver] i will get that warn


when my app become active i call [connecttoserver] and before it connect to server my app resign active and i call [disconnect] , and next time i will get that warn.....T-T

because i have to receive apple's remote notification so i have to disconnect sfs when it resign active
jianchic
Posts: 25
Joined: 08 Apr 2012, 16:38

Re: A connection attempt is already running

Postby jianchic » 26 Oct 2012, 11:13

does anyone can help me solve my problem please?

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 3 guests