Skip to content

Instantly share code, notes, and snippets.

@evanradcliffe
Created July 26, 2017 12:59
Show Gist options
  • Save evanradcliffe/3f639dbdaafa5fd7d732ac565cc567fa to your computer and use it in GitHub Desktop.
Save evanradcliffe/3f639dbdaafa5fd7d732ac565cc567fa to your computer and use it in GitHub Desktop.
Client file from class
#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