diff options
Diffstat (limited to '03_exercise/cli')
-rwxr-xr-x | 03_exercise/cli/client | bin | 22816 -> 22904 bytes | |||
-rw-r--r-- | 03_exercise/cli/client.c | 12 |
2 files changed, 8 insertions, 4 deletions
diff --git a/03_exercise/cli/client b/03_exercise/cli/client Binary files differindex abcfd45..eb8470f 100755 --- a/03_exercise/cli/client +++ b/03_exercise/cli/client diff --git a/03_exercise/cli/client.c b/03_exercise/cli/client.c index 3cd6f1b..a98942d 100644 --- a/03_exercise/cli/client.c +++ b/03_exercise/cli/client.c @@ -10,6 +10,8 @@ #define PORT 9000 #define HOST "127.0.0.1" +#define BUF_SIZE 256 + static inline void die(const char *msg) { perror(msg); exit(-1); @@ -21,7 +23,7 @@ int main() { .sin_port = htons(PORT), .sin_addr.s_addr = inet_addr(HOST) }; - char buf[256]; + char buf[BUF_SIZE]; int cfd; if ((cfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) @@ -35,6 +37,7 @@ int main() { __ssize_t length; while (1) { + printf("%s > ", HOST); if ((length = getline(&line, &cap, stdin)) < 0) { fprintf(stderr, "Failed to read from STDIN"); fflush(stderr); @@ -54,13 +57,14 @@ int main() { strncpy(buf, line, strlen(line)); - if (write(cfd, buf, sizeof(buf)) < 0) + if (write(cfd, buf, BUF_SIZE) < 0) die("Could not send message"); - if (read(cfd, buf, sizeof(buf)) < 0) + if (read(cfd, buf, BUF_SIZE) < 0) die("Could not receive message"); - printf("$> %s\n", buf); + printf("%s\n", buf); + memset(buf, 0, BUF_SIZE); } close(cfd); |