title: Which method to choose when developing a simple iOS Chat Application
body: <p>I have to develop a simple chat application for iOS devices.
  I tried to do this with this:</p>
  
  <p>When I run my application I call this method:</p>
  
  <pre><code>-(void) NewChatMessages{
  
  // Create the asynchronous request.
  NSString *chatURL = [NSString stringWithFormat: @"http://www.example.com/chat.php"];
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:chatURL] 
  cachePolicy:NSURLRequestUseProtocolCachePolicy
  timeoutInterval:10.0];
  
  [request setHTTPMethod:@"POST"];
  
  NSString *boundary = @"---------------------------234213413243214124321456566";
  NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
  [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
  
  NSMutableData *body = [NSMutableData data];
  
  [body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSASCIIStringEncoding]];
  [body appendData:[@"Content-Disposition: form-data; name=\"myTel\"\r\n\r\n" dataUsingEncoding:NSASCIIStringEncoding]];
  [body appendData:[[NSString stringWithFormat:@"%@",myTel] dataUsingEncoding:NSASCIIStringEncoding]];
  [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSASCIIStringEncoding]];
  
  [request setHTTPBody:body];
  
  // Create url connection and fire request
  chatConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  }
  </code></pre>
  
  <p>This request, calls a php script that checks if there are new messages for me or not:</p>
  
  <pre><code>$myTel = $_POST['myTel'];
  
  $exist=mysql_query("SELECT * from chat WHERE tel = '$myTel'");
  $num_rows = mysql_num_rows($esiste);
  if($num_rows &gt; 0){
  
      //there is a new chat message for me! (maybe it's not only one)
      echo "1";
  }
  else{
  
      //there aren't new chat messages for me
      echo "0";
  }
  </code></pre>
  
  <p>When I receive the response (using URLRequest delegate), if I received 1, I download new messages, else nothing.
  Then I call this method again (every time I receive a response) to create a new URL connection and check if there are new chat messages for me.
  This solution works fine, but my question is, is this the right method to develop a chat application?
  Isn't this method too recursively and isn't there an excessive memory and data usage?</p>