From cf700d07879db7e7c7b25e0c062f9e4a265fdeb6 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 5 Mar 2017 13:51:34 +0330 Subject: the received message is no longer overwritten. things are displayed correctly. --- daemon/mutatorclient.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'daemon') diff --git a/daemon/mutatorclient.c b/daemon/mutatorclient.c index dfc0ec4..5686783 100644 --- a/daemon/mutatorclient.c +++ b/daemon/mutatorclient.c @@ -55,7 +55,6 @@ int main(int argc, char *argv[]) perror("connect failed.error."); return 1; } - puts("connected."); /*keep communicating with the server.*/ @@ -64,18 +63,29 @@ int main(int argc, char *argv[]) printf("enter massage: "); /*@DEVI-should later do something about reading from stdin*/ - if (fgets(message, 2000, stdin) == NULL) + if (fgets(message, 4000, stdin) == NULL) { puts("could not read from stdin"); } puts("read from stdin."); + if (strncmp(message, "end_comm", 8) == 0) + { + puts("client terminated."); + break; + } + /*send some data*/ if (send(sock, message, strlen(message), 0) < 0) { puts("send fialed."); return 1; } + puts("message sent."); + puts(message); + + sleep(1); + fflush(stdin); /*recieve a reply from the server*/ if (recv(sock, server_reply, 2000, 0) < 0) @@ -87,12 +97,12 @@ int main(int argc, char *argv[]) puts("server reply: "); puts(server_reply); -#if 0 - if (strncmp(server_reply, "end_comm", strlen(server_reply))) + for (int i = 0; i < 2000; ++i) { - break; + server_reply[i] = 0; } -#endif + + fflush(stdout); } close(sock); -- cgit v1.2.3