more informative message

This commit is contained in:
Gregory Gauthier 2026-03-26 14:42:10 +00:00
parent b73bfb2db1
commit 37c20f8096

View File

@ -1,4 +1,4 @@
/* metric_client.c - STRICT C89/C90 clean live client with unsub */ /* metric_client.c - FINAL STRICT C89/C90 clean live client with unsub */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -77,7 +77,7 @@ int main(void)
perror("connect"); close(sock); exit(1); perror("connect"); close(sock); exit(1);
} }
printf("Connected to 127.0.0.1:%d (clean C89 client)\n", PORT); printf("Connected to 127.0.0.1:%d (FINAL clean C89 demo client)\n", PORT);
print_wire_comparison(); print_wire_comparison();
printf("Commands: ping | get <metric> | sub <metric> <ms> | unsub | quit\n"); printf("Commands: ping | get <metric> | sub <metric> <ms> | unsub | quit\n");
@ -98,7 +98,6 @@ int main(void)
break; break;
} }
/* 1. Async message from server */
if (FD_ISSET(sock, &readfds)) { if (FD_ISSET(sock, &readfds)) {
if (recv_exact(sock, header, HEADER_SIZE) != HEADER_SIZE) break; if (recv_exact(sock, header, HEADER_SIZE) != HEADER_SIZE) break;
@ -109,7 +108,6 @@ int main(void)
if (recv_exact(sock, payload, len) != len) break; if (recv_exact(sock, payload, len) != len) break;
} }
/* Clear current input line */
printf("\r\x1b[2K"); printf("\r\x1b[2K");
if (type == MSG_PONG) { if (type == MSG_PONG) {
@ -130,7 +128,6 @@ int main(void)
printf("> "); fflush(stdout); printf("> "); fflush(stdout);
} }
/* 2. User input */
if (FD_ISSET(0, &readfds)) { if (FD_ISSET(0, &readfds)) {
if (fgets(line, sizeof(line), stdin) == NULL) break; if (fgets(line, sizeof(line), stdin) == NULL) break;
line[strcspn(line, "\n")] = '\0'; line[strcspn(line, "\n")] = '\0';
@ -164,7 +161,7 @@ int main(void)
printf(" Unsubscribed (push stopped)\n"); printf(" Unsubscribed (push stopped)\n");
} }
else if (line[0] != '\0') { else if (line[0] != '\0') {
printf(" Unknown command.\n"); printf(" Unknown command: '%s'\n", line);
} }
printf("> "); fflush(stdout); printf("> "); fflush(stdout);