/* chatclient.c - a simple chat demo * (based on echoclient.c) */ #include "csapp.h" void chat_receive(int connfd); void chat_send(int connfd); int main(int argc, char **argv) { int clientfd; int status; pid_t pid; char *host, *port, buf[MAXLINE]; if (argc != 3) { fprintf(stderr, "usage: %s \n", argv[0]); exit(0); } host = argv[1]; port = argv[2]; clientfd = Open_clientfd(host, port); if (pid = Fork()){ // -- parent -- chat_send(clientfd); // loop: send user input to remote process // done when user types control-D (signaling end-of-file) kill(pid, SIGINT); // ... so get rid of child process Close(clientfd); exit(0); } else { // -- child -- chat_receive(clientfd); // loop: receive lines, write to terminal // stopped by parent when user input ends. } }