home_page.c 470 B

123456789101112131415161718192021222324
  1. #include "web.h"
  2. void
  3. home_page(const char *host, const char *fname)
  4. {
  5. int fd, n;
  6. char line[MAXLINE];
  7. fd = Tcp_connect(host, SERV); /* blocking connect() */
  8. n = snprintf(line, sizeof(line), GET_CMD, fname);
  9. Writen(fd, line, n);
  10. for ( ; ; ) {
  11. if ( (n = Read(fd, line, MAXLINE)) == 0)
  12. break; /* server closed connection */
  13. printf("read %d bytes of home page\n", n);
  14. /* do whatever with data */
  15. }
  16. printf("end-of-file on home page\n");
  17. Close(fd);
  18. }