// Clnt.C: Experiment with pth and I/O, paired with Svr.C. #include #include #include #include #include #include main(int argc, char **argv) { int SD,MsgSize; struct sockaddr_in Addr; struct hostent *HostPtr; int N; int Port; Port = atoi(argv[2]); /* open a socket */ SD = socket(AF_INET,SOCK_STREAM,0); /* set up for an Internet connection to the host whose name was specified by the user on the command line */ Addr.sin_family = AF_INET; Addr.sin_port = Port; /* get IP address of host */ HostPtr = gethostbyname(argv[1]); memcpy(&Addr.sin_addr.s_addr, HostPtr->h_addr_list[0],HostPtr->h_length); /* OK, now connect */ if (connect(SD,(sockaddr *) &Addr,sizeof(Addr)) < 0) perror(NULL); while (1) { scanf("%d",&N); write(SD,&N,1); read(SD,&N,1); printf("%d\n",N); } }