title: NSStreams Crashing Program!
body: <p>All,</p>
  
  <p>I've run it down to this point by commenting, breakpoints, etc. The program crashes at the marked code. </p>
  
  <pre><code>-(void) initNetworkCommunication
  {
      CFReadStreamRef readStream;
      CFWriteStreamRef writeStream;
      CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"192.168.17.1", 2004, &amp;readStream, &amp;writeStream);
  
      inputStream = (NSInputStream *)readStream;
      outputStream = (NSOutputStream *)writeStream;
      [inputStream setDelegate:self];
      [outputStream setDelegate:self];
      [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
      [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  
      [inputStream open];//WHY MUST YOU CRASH HERE
      [outputStream open];//WHY MUST YOU CRASH HERE ALSO!!?!?
  
      NSLog(@"She be opened, sir!");
  }
  </code></pre>
  
  <p>It doesn't crash if I comment out both of those, but it crashes if I comment out either one (so i.e. they are both causing the program to crash). There is no information that gets posted in the debugger either. All it does is send me to main.m and show me</p>
  
  <p>"Thread 1: Program received signal: "EXC_BAD_ACCESS".</p>
  
  <p>Thanks for the help in advance!</p>
  
  <p><strong>Edit: Here is my delegate method, but it doesn't even present the second active line in the log.</strong> </p>
  
  <pre><code>- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
  
      NSLog(@"stream event %i", streamEvent); //this doesn't post in the log when stream opened...
  
      switch (streamEvent) {
  
          case NSStreamEventOpenCompleted:
              NSLog(@"Stream opened");
              break;
          case NSStreamEventHasBytesAvailable:
  
              if (theStream == inputStream) {
  
                  uint8_t buffer[1024];
                  int len;
  
                  while ([inputStream hasBytesAvailable]) {
                      len = [inputStream read:buffer maxLength:sizeof(buffer)];
                      if (len &gt; 0) {
  
                          NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
  
                          if (nil != output) {
  
                              NSLog(@"server said: %@", output);
                              //[self messageReceived:output];
  
                          }
                      }
                  }
              }
              break;
  
  
          case NSStreamEventErrorOccurred:
  
              NSLog(@"Can not connect to the host!");
              break;
  
          case NSStreamEventEndEncountered:
  
              [theStream close];
              [theStream removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
              //[theStream release];
              theStream = nil;
  
              break;
          default:
              NSLog(@"Unknown event");
      }
  
  } 
  </code></pre>