Created
July 26, 2017 12:59
-
-
Save evanradcliffe/3f639dbdaafa5fd7d732ac565cc567fa to your computer and use it in GitHub Desktop.
Client file from class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "csapp.h" | |
/* usage: ./echoclient host port */ | |
int main(int argc, char **argv) | |
{ | |
int clientfd, port; | |
char *host, buf[MAXLINE]; | |
rio_t rio; | |
host = argv[1]; | |
port = atoi(argv[2]); | |
clientfd = Open_clientfd(host, port); | |
Rio_readinitb(&rio, clientfd); | |
printf("Enter message:"); fflush(stdout); | |
while (Fgets(buf, MAXLINE, stdin) != | |
NULL) { | |
Rio_writen(clientfd, buf, strlen(buf)); | |
Rio_readlineb(&rio, buf, MAXLINE); | |
printf("Echo:"); | |
Fputs(buf, stdout); | |
printf("Enter message:"); | |
fflush(stdout); | |
} | |
Close(clientfd); | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment