0

..and my app is still running!

There is this question about what happens when it goes to sleep + wakes up. I know it's calling:

- (void)AppDidBecomeActive:(NSNotification *)notification {

    if(jsocket){
        [jsocket release];
    }
    jsocket = [[johnsocket alloc] init];

    if(![jsocket connectViaSocket:(NSString*)ipaddress port:@"3660"]){
        //port 3660 is the XML port!!! good thing to know... 3663 is the binary protocol port.  yay!
        NSLog(@"error connecting from rooms page");
    }
}

(note: I'm using Asyncsocket.m, which is a great class that help manage sockets and such.. that's what jsocket is an instance of. This is a tcp client application.)

I actually had an alert popup in this function to make sure it was being called.. you see, the iphone/itouch don't go to sleep while plugged into USB, making this a more difficult situation to debug.

So my question is, how can I make it not crash?

Community
  • 1
  • 1
cmos
  • 629
  • 1
  • 7
  • 13

1 Answers1

3

Unless you have very full control over the server, there is nothing you can do to simply "wake up" a socket after an arbirtary time asleep. the remote server will probably have closed the connection after a timeout - that is what you should assume anyway.

You will have to re-initiate the connection and sync your state with the server from scratch.

Rog
  • 17,070
  • 9
  • 50
  • 73