title: How to send and receive bytes with socket apis?
body: <p>Hi i have written a server application which accepts a name from the client which usually is a file name.It opens the file ,reads the contents into a buffer and then transmits the buffer over the ethernet using <code>send()</code>.But the problem arises in the client side where all the bytes are not received successfully.I receive only a part of what i send.</p>
  
  <p>For your reference ,here's the code snippet for the server side: </p>
  
  <p><strong>Server</strong>:</p>
  
  <pre><code>fp = fopen(filename,"r+");  
          strcpy(str,"");
          fseek(fp, 0L, SEEK_END);
          size = ftell(fp);
          fseek(fp, 0L, SEEK_SET);
          fread(str, size, 1,fp);
          fclose(fp); 
          printf("Size of the file is : %d\n",size);
          sprintf(filename, "%d", size);
          n = send(nsd, filename, strlen(filename), 0);
  
  while(size &gt; 0){
              n = send(nsd, str, strlen(str), 0);
              printf("%d bytes sent successfully\n",n);           
              if(n == 0) break;
              sentbytes = sentbytes + n;
              size = size - sentbytes;
          }
  </code></pre>
  
  <p>Please help me with writing the client app.I am currently confused about how to go about writing it.Shall i place the <code>recv()</code> part in a <code>while(1)</code> loop so that the client keeps running until all the bytes have been received successfully?</p>