title: NSInputStream does not call Delegate (stream:handleEvent:)
body: <p>I searched the web for a long time...I didn't find an answer for my issue, so I decided to post here.
  I try to establish a connection to a NNTP-server using NSStream.</p>
  
  <p>In a test-program, I open the streams and send a message. The delegate-method (<code>stream:handleEvent:</code>) is called twice for the output-stream (<code>NSStreamEventOpenCompleted</code>, <code>NSStreamEventHasSpaceAvailable</code>) but <strong>never</strong> for the input-stream!</p>
  
  <p>Why does the input stream never call the delegate? Any ideas?</p>
  
  <p>Basically, the code looks like this:</p>
  
  <p>init and open streams:</p>
  
  <pre><code>CFReadStreamRef tmpiStream;
  CFWriteStreamRef tmpoStream;
  
  CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)SERVER, PORT, &amp;tmpiStream, &amp;tmpoStream);
  
  iStream = (__bridge NSInputStream *) tmpiStream;
  oStream = (__bridge NSOutputStream *)tmpoStream;
  
  [iStream setDelegate:self];
  [oStream setDelegate:self];
  
  [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  
  [iStream open];
  [oStream open];
  </code></pre>
  
  <p>send message:</p>
  
  <pre><code>NSData *data = [[NSData alloc] initWithData:[messageString dataUsingEncoding:NSASCIIStringEncoding]];
  [oStream write:[data bytes] maxLength:[data length]];
  </code></pre>
  
  <p>receive messages:</p>
  
  <pre><code>-(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
  {
      NSLog(@"EventCode: %i", eventCode);
      //switch-case-statement...(using constants - NSStreamEventOpenCompleted...)
  }
  </code></pre>
  
  <p>The class which contains that code inherits from NSObjects and implements <code>NSStreamDelegate</code>.
  (iOS5 with ARC)</p>
  
  <p>Thx for any help!</p>
  
  <p>EDIT:
  I just tried "polling" after opening streams like this - it's working:</p>
  
  <pre><code>while (![iStream hasBytesAvailable])
  {}
  uint8_t buffer[1024];
  int len;
  NSString *str = @"";
  
  while ([iStream hasBytesAvailable]) 
  {
      len = [iStream read:buffer maxLength:sizeof(buffer)];
      if (len &gt; 0) 
      {
          NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSISOLatin1StringEncoding];
  
          if (output != nil) 
          {
              str = [str stringByAppendingString:output];
          }
      }
  }
  NSLog(@"Response: %@", str);
  </code></pre>
  
  <p>But, for sure, I still need a better (async) solution ;)</p>