#include #include #include #include "sockettome.h" typedef struct { FILE *fin; FILE *fout; } Arg; void *reader(void *arg) { Arg *a; char buf[1000]; a = (Arg *) arg; while (fgets(buf, 1000, a->fin) != NULL) { fputs(buf, a->fout); fflush(a->fout); } return NULL; } main(int argc, char **argv) { /* Not error checking the command line */ int fd; pthread_t tid1, tid2; Arg a1, a2; fd = request_connection(argv[1], atoi(argv[2])); a1.fin = stdin; a1.fout = fdopen(fd, "w"); a2.fin = fdopen(fd, "r"); a2.fout = stdout; pthread_create(&tid1, NULL, reader, (void *) &a1); pthread_create(&tid2, NULL, reader, (void *) &a2); pthread_exit(NULL); }