title: Writing send_all and recv_all functions for sockets in C
body: <p>I am a new C programmer and so you will have to excuse my lack of knowledge. I am trying to use sockets in C on a windows machine to send data back and forth between a client and server. I am using the tools of cygwin with the codeblocks IDE.  Simple send and receives were not working and so after some searching I was under the impression my problem was I needed a send_all and recv_all function. I have written the following two functions but receive seems to always get stuck in an infinite loop. I am not really sure why. </p>
  
  <pre><code>void send_all(int socket, void *buffer, int length) {
      size_t i = 0;
      for (i = 0; i &lt; length; i += send(socket, buffer, length - i, 0)){
          printf("Completed: %d bytes \r", i);
      }
      printf("Send Completed: %d bytes \n", length);
  }
  
  void recv_all(int sockfd, void *buffer, int length){
      size_t i = 0;
      for (i = 0; i &lt; length; i+= recv(sockfd, buffer + i, length - i, 0)){
          printf("Completed: %d bytes \r", i);
      }
      printf("Receive Completed: %d bytes \n", length);
  }
  </code></pre>
  
  <p>I am wondering if it is because the receive doesn't know how many bytes the send is sending it. All advice is appreciated but please keep it constructive. Thanks.</p>