title: writing on a stream via TCP but no response
body: <p>I want to read out the Vehicle Identification Number (VIN) of a car via an OBD WiFi Adapter.
  Pinging the adapter is possible and it got an fix IP Adress and Port.</p>
  
  <p>Now i wanted to send the VIN-request on the Stream, but nothing happens.</p>
  
  <p>My .h file</p>
  
  <pre><code>@interface Communicator : NSObject &lt;NSStreamDelegate&gt; {
  @public
  
  NSString *host;
  int port;
  }
  
  - (void)setup;
  - (void)open;
  - (void)close;
  - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)event;
  - (void)readIn:(NSString *)s;
  - (void)writeOut:(NSString *)s;
  
  @end
  </code></pre>
  
  <p>My .m file</p>
  
  <pre><code>#import "Communicator.h"
  
  CFReadStreamRef readStream;
  CFWriteStreamRef writeStream;
  NSInputStream *inputStream;
  NSOutputStream *outputStream;
  
  @implementation Communicator
  
  - (void)setup {
  NSURL *url = [NSURL URLWithString:host];
  
  NSLog(@"Setting up connection to %@ : %i", [url absoluteString], port);
  
  CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)[url host], port, &amp;readStream, &amp;writeStream);
  
  if(!CFWriteStreamOpen(writeStream)) {
      NSLog(@"Error, writeStream not open");
      return;
  }
  [self open];
  
  NSLog(@"Status of outputStream: %i", [outputStream streamStatus]);
  return;
  }
  
  - (void)open {
  NSLog(@"Opening streams.");
  
  inputStream = (__bridge NSInputStream *)readStream;
  outputStream = (__bridge NSOutputStream *)writeStream;
  
  [inputStream setDelegate:self];
  [outputStream setDelegate:self];
  
  [inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  [outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
  
  [inputStream open];
  [outputStream open];
  
  if ([inputStream hasBytesAvailable])
  {
      NSLog(@"We can recieve something from the InputStream");
  }
  if ([outputStream hasSpaceAvailable])
  {
      NSLog(@"We can send something trough the OutputStream");
  }
  
  }
  
  - (void)close {
  NSLog(@"Closing streams.");
  ...
  }
  
  - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)event {
  NSLog(@"Stream triggered.");
  
  NSLog(@"event: %u", event);
  
  switch(event) {
      case NSStreamEventHasSpaceAvailable: {
          if(stream == outputStream) {
              NSLog(@"outputStream is ready.");
          }
          break;
      }
      case NSStreamEventHasBytesAvailable: {
          if(stream == inputStream) {
              NSLog(@"inputStream is ready.");
  
              uint8_t buf[1024];
              unsigned int len = 0;
  
              len = [inputStream read:buf maxLength:1024];
  
              if(len &gt; 0) {
                  NSMutableData* data=[[NSMutableData alloc] initWithLength:0];
  
                  [data appendBytes: (const void *)buf length:len];
  
                  NSString *s = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
  
                  [self readIn:s];
  
              }
          }
          break;
      }
      default: {
          NSLog(@"Stream is sending an Event: %i", event);
  
          break;
      }
  }
  }
  
  - (void)readIn:(NSString *)s {
  NSLog(@"Reading in the following:");
  NSLog(@"%@", s);
  }
  
  - (void)writeOut:(NSString *)s {
  uint8_t *buf = (uint8_t *)[s UTF8String];
  [outputStream write:buf maxLength:strlen((char *)buf)];
  NSLog(@"Status of outputStream: %i", [outputStream streamStatus]);
  
  NSError *theError = [outputStream streamError];
  NSLog(@"Error: %@", theError);
  
  NSLog(@"Writing out the following:");
  NSLog(@"%@", s);
  }
  
  @end 
  </code></pre>
  
  <p>my main</p>
  
  <pre><code>@autoreleasepool {
  
  Communicator *c = [[Communicator alloc] init];
  
  c-&gt;host = @"https://169.254.1.10";
  //c-&gt;host = @"http://169.254.1.10";
  //c-&gt;host = @"169.254.1.10";
  c-&gt;port = 23;
  
  [c setup];
  [c open];
  
  [c writeOut:@"0902"];
  
  do {
  } while (1);
  
           }
  return 0;
  }
  </code></pre>
  
  <p>console says this:</p>
  
  <pre><code>2012-12-13 16:22:41.319 obdlink[1940:f803] Setting up connection to https://169.254.1.10 : 23
  2012-12-13 16:22:55.409 obdlink[1940:f803] Opening streams.
  2012-12-13 16:23:16.504 obdlink[1940:f803] Status of outputStream: 1
  2012-12-13 16:23:20.878 obdlink[1940:f803] Opening streams.
  2012-12-13 16:23:33.858 obdlink[1940:f803] Status of outputStream: 2
  2012-12-13 16:23:46.092 obdlink[1940:f803] Error: (null)
  2012-12-13 16:23:59.011 obdlink[1940:f803] Writing out the following:
  2012-12-13 16:24:01.104 obdlink[1940:f803] 0902
  </code></pre>
  
  <p>"0902" is the command that should return me a 5x5 multi-frame response with the VIN.</p>
  
  <p>I really tried everything i could imagine or i found in the world wide web.
  Im stuck and dont know further, i hope anyone here can help me.</p>