Respond to Client in C Programming

How to write a Respond to Client in C Program ?


Solution:

  1.       // TODO: respond to client
  2.                 if (dprintf(cfd, "HTTP/1.1 200 OK\r\n") < 0)
  3.                 {
  4.                     continue;
  5.                 }
  6.                 if (dprintf(cfd, "Connection: close\r\n") < 0)
  7.                 {
  8.                     continue;
  9.                 }
  10.                 if (dprintf(cfd, "Content-Length: %i\r\n", length) < 0)
  11.                 {
  12.                     continue;
  13.                 }
  14.                 if (dprintf(cfd, "Content-Type: %s\r\n", type) < 0)
  15.                 {
  16.                     continue;
  17.                 }
  18.                 if (write(cfd, body, length) == -1)
  19.                 {
  20.                     continue;
  21.                 }


Learn More :