How to write a Respond to Client in C Program ?
Solution:
- // TODO: respond to client
- if (dprintf(cfd, "HTTP/1.1 200 OK\r\n") < 0)
- {
- continue;
- }
- if (dprintf(cfd, "Connection: close\r\n") < 0)
- {
- continue;
- }
- if (dprintf(cfd, "Content-Length: %i\r\n", length) < 0)
- {
- continue;
- }
- if (dprintf(cfd, "Content-Type: %s\r\n", type) < 0)
- {
- continue;
- }
- if (write(cfd, body, length) == -1)
- {
- continue;
- }