Search code examples
iphoneobjective-cconnectionwifinsstream

NSStreamEventErrorOccurred triggered even if the network is pretty strong signal


I have implemented the NSStream delegate. I have implemented the same as Witap Application

In that, I have implemented handleEvent delegate

- (void) stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode{

  switch(eventCode) {

           case NSStreamEventOpenCompleted:
              {
                 [tcpServer release];
                 tcpServer = nil;               
                 break;
              }
          case NSStreamEventHasBytesAvailable:    
              {
                  //done my stuff here
              }
         case NSStreamEventErrorOccurred:    
              {


    UIAlertView *wifiLostAlert = [[UIAlertView alloc] initWithTitle:@"Wifi
 connection error" message:@"" delegate:nil cancelButtonTitle:@"Continue" otherButtonTitles:nil];
                     [wifiLostAlert show];
                     [wifiLostAlert release];
                      wifiLostAlert = nil;

              }

    }

In my client site, they reported an issue as

"Multiple time when we was either trying to send a message to the learner or synching devices she got the following message: “Wifi connection error. Same happend at 2 different networks and it doesnot recover quickly even if the network is pretty strong signal."

Unfortunately, I am unable to reproduce this issue in my site and it's working fine in another client site too!!.

Any clue's regarding the issue. Any help on this is appreciated.

Thank you.


Solution

  • I would recommend you supply the client with an updated version that displays more information about what error is actually occurring.

    You can get more information about the error using:

    NSError* error = [stream streamError];
    

    You can find more information about NSError at NSError Class Reference.

    Something like this might work in your case:

    NSString* errorMessage = [NSString stringWithFormat:@"%@ (Code = %d")",
                                       [error localizedDescription],
                                       [error code]];
    

    Then change your UIAlertView to this:

    UIAlertView *wifiLostAlert = [[UIAlertView alloc] 
                         initWithTitle:@"Stream Error" 
                               message:errorMessage
                              delegate:nil         
                     cancelButtonTitle:@"Continue" 
                     otherButtonTitles:nil];
    

    This won't solve the problem but will give both you and your client more information about the root cause is.

    For example, you may find the error is "Connection refused." which would point to a problem not with WiFi signal strength but in the server-side software.

    Good luck!