title: using NSInputStream/NSOutputStream to communicate over TCP (iPhone)
body: <p>Is it possible to do TCP communications using NSInputStream/NSOutputStream on iPhone? The example apple gives in their documentation uses [NSStream getStreamsToHost] and that isn't supported on iPhone. I have seen other posts which use CFStream to set up the socket and then bridge to NSStream, is that the only supported way?</p>
  
  <p>Based on the documentation it seems something like this should work in theory:</p>
  
  <pre><code>//input stream
  NSURL *url = [[NSURL alloc] initWithString:@"10.252.1.1:8080"];
  
  iStream = [NSInputStream inputStreamWithURL:url];
  [iStream setDelegate:self];
  
  [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  [iStream open];
  
  oStream = [NSOutputStream outputStreamWithURL:url append:true];
  [oStream setDelegate:self];
  
  [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  [oStream open];
  </code></pre>
  
  <p>However there are two problems with this:</p>
  
  <p>1) If I do just the iStream part I never see any events called on my delegate.</p>
  
  <p>2) The outputStreamWithURL fails with a cryptic "EXC_BAD_ACCESS" error message which comes from within CFWriteStreamSetProperty</p>