title: Keeping a socket connection alive in iOS
body: <p>I have the following code written in Objective-C that writes data to a socket. The server is running node.js on top of Ubuntu:</p>
  
  <pre><code>NSString *url = @"anIPAddress";        
  CFReadStreamRef readStream;
  CFWriteStreamRef writeStream;            
  CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)url, 9000, &amp;readStream, &amp;writeStream);
  self.inputStream = (NSInputStream *)readStream;            
  self.outputStream = (NSOutputStream *)writeStream;
  [self.inputStream setDelegate:self];            
  [self.outputStream setDelegate:self];            
  [self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];            
  [self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];            
  [self.inputStream open];            
  [self.outputStream open];
  </code></pre>
  
  <p>I am able to connect to the server and send information. However I noticed the connection times out after a few minutes (I think 5 minutes or so?). How can I keep this connection alive? I know there is a disconnect because the same thing happens if I connect to the server under Terminal, I have to keep that connection alive. I imagine the same thing is happening in my code. Thanks for your help!</p>