title: Two way socket communication
body: <p>I'm trying to write a simple two way socket communication using C. So far, the main while loop for my client.c file looks like this:</p>
  
  <pre><code>while ( gets(str) != NULL ) {
  sSize = send(s, str, strlen(str), 0);
  if ( len != strlen(str) ) {
    exit(1);
  }
  
  else {
     rSize  =  recv(s, buffer, 64, 0);
     buf[rSize] = '\0';
     printf("%s\n", buffer);
   }
  }
  </code></pre>
  
  <p>while loop in sever.c looks like this:</p>
  
  <pre><code>while ( 1 ) {
  gets(str);
  send(p, str, strlen(str), 0);
  
    rSize = recv(p, buffer, 32, 0);   
    if ( rSize &lt; 0 ) {
      exit(1);
    }
   buf[len] = '\0';
    else{
      printf("%s\n", buffer);
    }
  }
  </code></pre>
  
  <p>The program compiles normally and I can establish connection between both machines, but when I send message either from client or server, I get an anomaly:</p>
  
  <p>Sending message 'hi' from client</p>
  
  <pre>client -------------------------- server
  hi                           
  </pre>
  
  <p>If I go to server to send 'you' message, I get:</p>
  
  <pre>client -------------------------- server
  hi                           
                                    you
  you                               hi
  </pre>
  
  <p>Not sure exactly how this is, but what I'm trying to achieve is that, whenever message is sent from either client or server, it should display immediately on the other side.</p>