title: HTTP Server in C not displaying image
body: <p>I am trying to create a simple HTTP-server using C. Here's my code</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;string.h&gt;
  
  #define PORT 8080
  int main(int argc, char const *argv[])
  {
      int server_fd, new_socket; long valread;
      struct sockaddr_in address;
      int addrlen = sizeof(address);
      
      // Only this line has been changed. Everything is same.
      char *hello = &quot;HTTP/1.1 200 OK\nContent-Type: image/jpeg\nContent-Length: 10000\n\n&lt;img src = \&quot;hello.jpeg\&quot; alt = \&quot;hello image\&quot;&gt;&quot;;
      
      // Creating socket file descriptor
      if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
      {
          perror(&quot;In socket&quot;);
          exit(EXIT_FAILURE);
      }
      
  
      address.sin_family = AF_INET;
      address.sin_addr.s_addr = INADDR_ANY;
      address.sin_port = htons( PORT );
      
      memset(address.sin_zero, '\0', sizeof address.sin_zero);
      
      
      if (bind(server_fd, (struct sockaddr *)&amp;address, sizeof(address))&lt;0)
      {
          perror(&quot;In bind&quot;);
          exit(EXIT_FAILURE);
      }
      if (listen(server_fd, 10) &lt; 0)
      {
          perror(&quot;In listen&quot;);
          exit(EXIT_FAILURE);
      }
      while(1)
      {
          printf(&quot;\n+++++++ Waiting for new connection ++++++++\n\n&quot;);
          if ((new_socket = accept(server_fd, (struct sockaddr *)&amp;address, (socklen_t*)&amp;addrlen))&lt;0)
          {
              perror(&quot;In accept&quot;);
              exit(EXIT_FAILURE);
          }
          
          char buffer[30000] = {0};
          valread = read( new_socket , buffer, 30000);
          printf(&quot;%s\n&quot;,buffer );
          write(new_socket , hello , strlen(hello));
          close(new_socket);
      }
      return 0;
  }
  </code></pre>
  <p>When Content-Type is <strong>text/html</strong> it is displaying text &quot;Hello world&quot;</p>
  <blockquote>
  <p>char *hello = &quot;HTTP/1.1 200 OK\nContent-Type: text\html\nContent-Length: 100\n\nHello world&quot;;</p>
  </blockquote>
  <p>but after changing it to <strong>image/jpeg</strong> for displaying image I am getting a <strong>black background</strong> instead of image.</p>
  <blockquote>
  <pre><code>char *hello = &quot;HTTP/1.1 200 OK\nContent-Type: image/jpeg\nContent-Length: 10000\n\n&lt;img src = \&quot;hello.jpeg\&quot; alt = \&quot;hello image\&quot;&gt;&quot;;
  </code></pre>
  </blockquote>
  <p>When I run this code, I get this in the output</p>
  <pre><code>GET / HTTP/1.1
  Host: localhost:8080
  Connection: keep-alive
  Cache-Control: max-age=0
  sec-ch-ua: &quot;Google Chrome&quot;;v=&quot;105&quot;, &quot;Not)A;Brand&quot;;v=&quot;8&quot;, &quot;Chromium&quot;;v=&quot;105&quot;
  sec-ch-ua-mobile: ?0
  sec-ch-ua-platform: &quot;Linux&quot;
  Upgrade-Insecure-Requests: 1
  User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
  Sec-Fetch-Site: none
  Sec-Fetch-Mode: navigate
  Sec-Fetch-User: ?1
  Sec-Fetch-Dest: document
  Accept-Encoding: gzip, deflate, br
  Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
  </code></pre>