title: NSURLConnection Fails with error codes -1001,-1005,1004 and also NSPOSIXErrorDomain Code=2
body: <p>We have more number of devices(200+) connected to network to communicate with server, often the connection fails and does not reconnect as mentioned in the question I am getting the mentioned errors.</p>
  
  <p>The code which we use to send request is</p>
  
  <pre><code>dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  
                  NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://ipaddress"];
  
                  NSMutableURLRequest *menuRequest=[[NSMutableURLRequest alloc]initWithURL:url];
  
  
  
                  NSURLResponse *response;
                  NSError *error=nil;
  
                  NSData *data = [NSURLConnection sendSynchronousRequest:menuRequest returningResponse:&amp;response error:&amp;error];
  
                  dispatch_async(dispatch_get_main_queue(), ^{
  
                      if(!error)
                      {
  
                          NSLog(@"Request Success");
                          NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData: data];
                          [xmlParser setDelegate:self];
                          [xmlParser parse];
                      }
                      else
                      {
                         NSLog(@"Failed with error-----%@",error);
                      }
                  });
              });
  </code></pre>
  
  <p>This request is sent every minute.</p>
  
  <p>It happens only in client environment we need to recover from this connection failure and reconnect(the next request does not get success even if the server is up).This happens in both iOS 7 &amp; 8.I went through some similar post but I am not able to get the exact reason and also the solution for these problems.Help me out guys.</p>