A connection attempt is already running

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

Moderators: Lapo, Bax

jianchic
Posts: 25
Joined: 08 Apr 2012, 16:38

A connection attempt is already running

Postby jianchic » 21 Oct 2012, 12:02

Hello
when i connect to server i get this error !
this is my code

Code: Select all

 if (!self.sfs) {
        [self setSfs:[[SmartFox2XClient smartFoxWithDebugMode:NO delegate:self] autorelease]];
        [self.sfs setUseBlueBox:NO];
    }
   
    [self.sfs connect:socket_ip port:9933];


There is no problem if i create a new SmartFox2XClient instance to connect to server . but what i want to know is how i can release the pre instance ,because of this my app now have a terrible memory leak .
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 21 Oct 2012, 12:37

I'm not sure why you want to release the previous intance, it would be better to simply disconnect and then reconnect the client:

Code: Select all

    [self.sfs disconnect];
    [self.sfs connect:(NSString *) port:(int)];


Only release the SFS when destroying the app.
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 » 21 Oct 2012, 12:43

when i connect to server i got this error "[SFS - WARN]A connection attempt is already running
2012-10-21 20:35:59.487 " and it will not connect to server at all , so i recreate a instance,
and when i call [self.sfs disconnect] i got this warning [SFS - INFO]You are not connected...
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 21 Oct 2012, 12:54

If a connection attempt is running, you've already tried to connect, so I wouldn't manually connect after that. Look at you're load config code:

Code: Select all

[client loadConfig:@"config.xml" connectOnSuccess:NO];


If you have connectOnSuccess:YES, then you're already attempting a connection so there is no need to manually connect.
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 » 21 Oct 2012, 12:59

i didn't use this meted [client loadConfig:@"config.xml" connectOnSuccess:NO];



i only call this [self.sfs connect:socket_ip port:9933]; is there any difference,

when i got this warning i wait for serial minutes but i really can't connect to server


i will have a try but do i have to load the config xml again when i reconnect to server?
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 21 Oct 2012, 13:08

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 » 21 Oct 2012, 13:13

i'm sorry please ! can you tell me what i have to do to solve this problem please! i'm really in a hurry, i have to upload my app today T-T, i have tried all the method you told me many times!
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 21 Oct 2012, 13:20

Hard to say without seeing you code. Can you post/attach your connection handling methods?
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 » 21 Oct 2012, 13:26

here is my code


Code: Select all


- (id)init{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationNotification:) name:UIApplicationDidEnterBackgroundNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationNotification:) name:UIApplicationWillEnterForegroundNotification object:nil];
    }
    return self;
}


- (void)handleApplicationNotification:(NSNotification *)notification {
    NSString *name = [notification name];
    if ([name isEqualToString:UIApplicationWillEnterForegroundNotification]) {
              trace(@"application will enter foreground");
             if (!self.sfs) {
                   [self setSfs:[[SmartFox2XClient smartFoxWithDebugMode:NO delegate:self] autorelease]];
                   [self.sfs setUseBlueBox:NO];
              } else {
                   [self.sfs disconnect];
              }
               [self.sfs connect:socket_ip port:9933];
    } else {
        trace(@"application will enter background");
        [self.sfs disconnect];
    }
}




i think this is the most important code ,other code are just login join room ....
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 21 Oct 2012, 13:36

There's not much much there regarding SFS - that's more of a general iOS issue. If you'd like to handle foreground/background toggle, use the disconnect and connect methods. First off, once you load the app the first time, load the config and auto connect - it should take milliseconds unless your architecture has some logic that prevents it.

Once the app goes into the background, call the disconnect method. When it enters the foreground, the connect. THere shouldn't be any issues there. Don't release the SFS client though, as this would be inefficient.
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 » 21 Oct 2012, 13:44

i really really don't understand how to solve this problem, can you please give me some code


do you mean

Code: Select all

- (void)handleApplicationNotification:(NSNotification *)notification {
    NSString *name = [notification name];
    if ([name isEqualToString:UIApplicationWillEnterForegroundNotification]) {
      static BOOL isFirst = YES;
      if(isFirst) {
         isFirst = NO;
         [self.sfs loadConfig:@"server_config.xml" connectOnSuccess:YES];
      } else {
         [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 » 21 Oct 2012, 16:37

You can do what you have, although setting a dedicated Bool variable I don't think is necessary. You can listen for the onConfigLoadSuccess event to make sure that you have your settings. After that checking if your SFS variable is null or not will do. Just check for isConnected when coming back into the foreground and if not, call the connect method.
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 » 21 Oct 2012, 16:59

but the problem is when coming back isConnected = NO but after i call the connect method i will get the warn message "A connection attempt is already running" and even i called “disconnect” , i can't connect to server at all
User avatar
A51Integrated
Posts: 240
Joined: 03 Jan 2012, 19:55
Location: Toronto, Canada
Contact:

Re: A connection attempt is already running

Postby A51Integrated » 21 Oct 2012, 17:21

The client will try to connect to the server automatically once connectivity is lost. Which will happen when the app goes into the background. So when it returns to the foreground, it attempt automatically to connect - that's why if you manually call connect, you get the warning.

If you can disconnect the client prior to the app moving to the background, then it won't act as if it has suddenly lost connectivity. You can use the applicationWillResignActive event. This way, the lost connection is manual as apposed to accidental.
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, 05:21

disconnect in applicationWillResignActive event is much better , but the warn message can also happen , can you tell me ,when it happen ,how can i disconnect it manually, because when i call [self.sfs disconnect] i will get a message "[SFS - INFO]You are not connected..." but after waiting for a long time i really can't login the server

Return to “SFS2X iPhone / iPad / OSX API”

Who is online

Users browsing this forum: No registered users and 22 guests