diff options
Diffstat (limited to '03_exercise/cli/client.c')
-rw-r--r-- | 03_exercise/cli/client.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/03_exercise/cli/client.c b/03_exercise/cli/client.c index a98942d..527c67c 100644 --- a/03_exercise/cli/client.c +++ b/03_exercise/cli/client.c @@ -10,7 +10,7 @@ #define PORT 9000 #define HOST "127.0.0.1" -#define BUF_SIZE 256 +#define BUF_SIZE 1024 static inline void die(const char *msg) { perror(msg); @@ -51,20 +51,24 @@ int main() { line[length - 1] = '\0'; // cut the line feed - if (strcmp(line, "exit") == 0) { - break; - } - strncpy(buf, line, strlen(line)); if (write(cfd, buf, BUF_SIZE) < 0) die("Could not send message"); + if (strcmp(line, "exit") == 0) { + free(line); + line = NULL; + break; + } + if (read(cfd, buf, BUF_SIZE) < 0) die("Could not receive message"); printf("%s\n", buf); memset(buf, 0, BUF_SIZE); + free(line); + line = NULL; } close(cfd); |