#include #include "socketfun.h" int read1000(int fd, char *chars) { int so_far, i; so_far = 0; while(so_far < 1000) { i = read(fd, chars+so_far, 1000-so_far); if (i == 0) return 0; so_far += i; } return 1; } main() { int sock; int fd; char chars[1000]; char output[20]; FILE *fout; int nchars; sock = serve_socket("cetus3a.cs.utk.edu", 15000); if (sock < 0) { perror("serve_socket"); exit(1); } fout = fopen("outfile", "w"); if (fout == NULL) { perror("fopen(outfile)"); exit(1); } nchars = 0; while (1) { fd = accept_connection(sock); if (read1000(fd, chars) != 0) { fwrite(chars, 1, 1000, fout); nchars += 1000; sprintf(output, "%d\n", nchars); write(fd, output, strlen(output)); } close(fd); } }