title: How to send html files with http protocol over tcp in c language?
body: <p>I 'm  writing a HTTP web server that can respond to <code>PUT</code>, <code>GET</code> , ... requests
  when <code>GET</code> request is sent from a browser , the browser should receives the related HTML file
  I have analyzed the <code>GET</code> request in the Wireshark it sends the whole HTML file of the website 
  and then the browser requests the rest of the files that are used in the HTML file</p>
  
  <p>My problem is that when I use the <code>send()</code> function and send and HTTP respond to the <code>GET</code> requests the body part of the HTTP message that contains the HTML file is not displayed correctly in the browser when it is read from a HTML file but when I type the HTML file into a string variable and give it to the <code>send()</code> function it works.</p>
  
  <p>here is my code:</p>
  
  <pre><code>char send_buffer[1000];
  FILE *sendFile = fopen("foo.txt", "r");
  while( !feof(sendFile) )
  {
  int numread = fread(send_buffer, sizeof(unsigned char), 1000, sendFile);
  if( numread &lt; 1 ) break; // EOF or error
  
  char *send_buffer_ptr = send_buffer;
  do
  {
      int numsent = send(connected, send_buffer_ptr, numread, 0);
      if( numsent &lt; 1 ) // 0 if disconnected, otherwise error
      {
          if( numsent &lt; 0 )
          {
              if( WSAGetLastError() == WSAEWOULDBLOCK )
              {
                  fd_set wfd;
                  FD_ZERO(&amp;wfd);
                  FD_SET(connected, &amp;wfd);
  
                  timeval tm;
                  tm.tv_sec = 10;
                  tm.tv_usec = 0;
  
                  if( select(0, NULL, &amp;wfd, NULL, &amp;tm) &gt; 0 )
                      continue;
              }
          }
  
          break; // timeout or error
      }
  
      send_buffer_ptr += numsent;
      numread -= numsent;
  }
  while( numread &gt; 0 );
  }
  </code></pre>
  
  <p>I have tested the code with the foo file containing the HTTP header and some HTML code as below:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Content-length: 60
  Content-Type: text/html
  
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;h1&gt;My First Heading&lt;/h1&gt;
  
  &lt;p&gt;My first paragraph.&lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I have also tries sending the header with a separate send function and the HTML file with another send function right after it.</p>