title: NSStream and Sockets, NSStreamDelegate methods not being called
body: <p>I've followed the guide <a href="http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Streams/Articles/NetworkStreams.html%23//apple_ref/doc/uid/20002277-1002597" rel="noreferrer">Setting Up Socket Streams</a> and have effectively duplicated that code in my class. No matter what I try the delegate methods just don't seem to get called.</p>
  
  <p>In the header file I have (basically):</p>
  
  <pre><code>@interface myClass : NSObject &lt;NSStreamDelegate&gt; {
      NSInputStream *inputStream;
      NSOutputStream *outputStream;
  }
  - (void)connect;
  @end;
  </code></pre>
  
  <p>The connect method:</p>
  
  <pre><code>- (void)connect {
      CFReadStreamRef readStream;
      CFWriteStreamRef writeStream;
  
      CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (CFStringRef)@"host.example.com", 1234, &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];
      [outputStream open];
  }
  </code></pre>
  
  <p>Also tried using <code>CFStreamCreatePairWithSocketToCFHost()</code> and <code>[NSStream getStreamsToHost:port:inputStream:outputStream:</code> - all with exactly the same result.</p>
  
  <p>I've set a breakpoint at the beginning of the <code>connect</code> method, stepped through every line and every pointer is valid and seems to point to the correct object.</p>
  
  <p>In GDB, after the <code>setDelegate</code> calls, <code>po [inputStream delegate]</code> prints <code>&lt;myClass: 0x136380&gt;</code> as expected, so it has set the delegate correctly.</p>
  
  <p>For the life of me I can't work out why it refuses to call the <code>stream:handleEvent:</code> method on my class:</p>
  
  <pre><code>- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode {
      NSLog(@"got an event");
  }
  </code></pre>
  
  <p>Hopefully I've missed something really simple and obvious and a second pair of eyes can spot my mistake.</p>
  
  <p>Thanks in advance to anyone who has the patience and taken the time to read this far!</p>