title: NSInputStream's NSStreamEventHasBytesAvailable never gets called
body: <p>I am creating an app similar to WiTap (but to connect many devices) and here is my problem: The application seems to connect the devices (they are displayed in table view controller. The delegate of <code>NSInput/OutputStream</code> says both streams are opened but when I send packet to <code>NSOutputStream</code> than the function on opposite device with <code>NSInputStream</code> doesn't get called <code>(NSStreamEventHasBytesAvailible</code> in <code>- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode)</code>.</p>
  
  <p>Here is the code that is doing the connection and sending and receiving ...</p>
  
  <pre><code>//Service was resolved
  - (void)netServiceDidResolveAddress:(NSNetService *)netService
  {
   //Get the streams from NSNetService
   NSInputStream *inStream = nil;
   NSOutputStream *outStream = nil;
   [netService getInputStream:&amp;inStream outputStream:&amp;outStream];
   [inStream setDelegate:self];
   [inStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
   [inStream open];
   [outStream setDelegate:self];
   [outStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
   [outStream open];
   [self.inStreams addObject:inStream];
   [self.outStreams addObject:outStream];
  
   //Add NSNetService between connected devices
   [self.resolvedServices addObject:netService];
   [self updateUI];
  }
  
  //event handling
  - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
  {
   switch (eventCode) {
      case NSStreamEventHasBytesAvailable:
          {
              NSMutableData *inBuffer = [[NSMutableData alloc] init];
              NSInputStream *inStream = (NSInputStream *)aStream;
              uint8_t buffer[3];
              NSInteger len = 0;
              NSInteger packetNumber = 0;
              len = [inStream read:buffer maxLength:3];
              if(len &gt; 0) {
                  [inBuffer appendBytes:buffer length:len];
                  [inBuffer getBytes:&amp;packetNumber length:len];
                  [self.delegate stream:inStream didReceivePacketNumber:[NSNumber numberWithInteger:packetNumber]];
              }
          } 
          break;
      case NSStreamEventHasSpaceAvailable:
          if ([aStream isKindOfClass:[NSOutputStream class]])
              NSLog(@"NSStream \"%@\" has space availible",aStream);
          break;
      case NSStreamEventOpenCompleted:
          if ([aStream isKindOfClass:[NSInputStream class]])
              NSLog(@"NSInputStream opened");
          else if ([aStream isKindOfClass:[NSOutputStream class]])
              NSLog(@"NSOutputStream opened");
          break;
      case NSStreamEventErrorOccurred:
          NSLog(@"NSStream \"%@\" occurred an error: %@",aStream,[aStream streamError]);
          break;
      case NSStreamEventEndEncountered:
          NSLog(@"Stream \"%@\" has been closed",aStream);
          [aStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
          [aStream close];
          NSUInteger index = 0;
          if ([aStream isKindOfClass:[NSOutputStream class]]) {
              index = [self.outStreams indexOfObject:aStream];
              [self.outStreams removeObject:aStream];
              [self.inStreams removeObjectAtIndex:index];
          } else if ([aStream isKindOfClass:[NSInputStream class]]) {
              index = [self.inStreams indexOfObject:aStream];
              [self.inStreams removeObject:aStream];
              [self.outStreams removeObjectAtIndex:index];
          }
          [self.availibleServices removeObjectAtIndex:index];
          [self.resolvedServices removeObjectAtIndex:index];
          break;
      default:
          break;
   }
  }
  
  //sending
  //Data pushing into NSStreams
  - (void)sendData:(NSData *)data toStream:(NSOutputStream *)aStream
  {
   if ([aStream hasSpaceAvailable]) {
      NSLog(@"%i",[aStream write:[data bytes] maxLength:[data length]]);
   }
  }
  </code></pre>
  
  <p>I tried to debug the project using Instruments (the network thing). It says packet is send and received but the event never occurs. Thank you for your help. If anyone wants I have no problem sending the whole project ...</p>