From 74abc79434fe895d0ca863e4d1d6c5c16b54f296 Mon Sep 17 00:00:00 2001 From: Niklas Halle Date: Mon, 1 Jun 2020 15:46:28 +0200 Subject: trying to connect server and shell, weird --- 03_exercise/cli/client | Bin 22904 -> 23056 bytes 03_exercise/cli/client.c | 14 +++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to '03_exercise/cli') diff --git a/03_exercise/cli/client b/03_exercise/cli/client index eb8470f..53ba0d8 100755 Binary files a/03_exercise/cli/client and b/03_exercise/cli/client differ 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); -- cgit v1.2.3-54-g00ecf