Page 2 of 2
Re: A connection attempt is already running
Posted: 22 Oct 2012, 13:19
by A51Integrated
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.
Re: A connection attempt is already running
Posted: 22 Oct 2012, 13:46
by jianchic
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];
}
}
Re: A connection attempt is already running
Posted: 22 Oct 2012, 13:55
by A51Integrated
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.
Re: A connection attempt is already running
Posted: 22 Oct 2012, 14:15
by jianchic
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
Re: A connection attempt is already running
Posted: 22 Oct 2012, 14:25
by A51Integrated
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];
}
Re: A connection attempt is already running
Posted: 22 Oct 2012, 15:44
by jianchic
this is always happened when the network environment is not so well
Re: A connection attempt is already running
Posted: 22 Oct 2012, 15:54
by A51Integrated
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.
Re: A connection attempt is already running
Posted: 22 Oct 2012, 15:58
by jianchic
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
Re: A connection attempt is already running
Posted: 26 Oct 2012, 11:13
by jianchic
does anyone can help me solve my problem please?