summaryrefslogtreecommitdiffstats
path: root/03_exercise/cli/client.c
diff options
context:
space:
mode:
authorNiklas Halle <niklas@niklashalle.net>2020-06-01 15:46:28 +0200
committerNiklas Halle <niklas@niklashalle.net>2020-06-01 15:46:50 +0200
commit74abc79434fe895d0ca863e4d1d6c5c16b54f296 (patch)
treec0fcf720bf72c6cd348ce6b8a3063861918fc609 /03_exercise/cli/client.c
parent85131d8acfca55810205af625d65358f006f3de7 (diff)
downloadbetriebssysteme-74abc79434fe895d0ca863e4d1d6c5c16b54f296.tar.gz
betriebssysteme-74abc79434fe895d0ca863e4d1d6c5c16b54f296.zip
trying to connect server and shell, weird
Diffstat (limited to '03_exercise/cli/client.c')
-rw-r--r--03_exercise/cli/client.c14
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);