title: send() and recv() functions
body: <p>I am attempting to set up a server/client model. The client will receive two matrices from the user, then send these two matrices to the server, which will then compute their product and send the result back to the client, which shall print the result. I encode the matrices as a C-string and send them to the server, where it should be decoded. My code looks as follows:</p>
  
  <p>The client sends the two matrices using the following code:</p>
  
  <pre><code>send_all( sockfd, send_str, strlen(send_str) );
  shutdown( sockfd, SHUT_WR ); // Close the write side of socket, since sending is done.
  </code></pre>
  
  <p>Where <code>send_all</code> is:</p>
  
  <pre><code>void send_all( int socket, char *data, size_t len )
  {
      size_t i;
      for( i = 0; i &lt; len; i += send( socket, data, len - i, 0 );
      {
          printf("%d bytes sent to server.\n", len - i); // To confirm send to user
      }
  }
  </code></pre>
  
  <p>My server then receives the the data as follows:</p>
  
  <pre><code>while( len = recv( connfd, buffer, MAX_LINE, 0 ) &gt; 0 )
  {
      printf("%d bytes read.\n", len); // To confirm receive to user.
      buffer[len] = '\0';
      strcat(input, buffer);
  }
  if( len &lt; 0 )
  {
      printf("Read error.");
  }
  </code></pre>
  
  <p>The server then parses the string and computes the product, then sending the data in the same manner as the client, where the client receives the data in the same manner as the server.</p>
  
  <p>When I run this program, the client prints that it has sent the correct number of bytes, for example:</p>
  
  <pre><code>406 bytes sent to server.
  </code></pre>
  
  <p>The server then prints (consistently, no matter the size of the string I send):</p>
  
  <pre><code>72720 bytes read.
  </code></pre>
  
  <p>and when attempting to print the string, it appears to be garbage.</p>
  
  <p>I am running the client and server in separate Cygwin terminals, using the local host 127.0.0.1, and it appears that they connect successfully.</p>
  
  <p>What am I doing wrong? Am I sending/receive the data in the correct manner? Will my method result in <code>input</code> being identical to <code>send_str</code>? Thank you for your help.</p>
  
  <p>EDIT: I have seen many questions on here and else where addressing difficulties with send() and recv() but I have found no explanation of why recv would be returning such a large number when only a much smaller number of bytes are sent. </p>