diff options
author | dweller <dweller@cabin.digital> | 2024-03-09 00:55:36 +0200 |
---|---|---|
committer | dweller <dweller@cabin.digital> | 2024-03-09 00:55:36 +0200 |
commit | 86d3f93ee338b28ab7d40aa83c129cf6b97ef4b7 (patch) | |
tree | 507a8d66932e6dea9b121dfcbf980f7925575c9f /c/sources/client.c |
Initial commit, 2 years later
Diffstat (limited to 'c/sources/client.c')
-rw-r--r-- | c/sources/client.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/c/sources/client.c b/c/sources/client.c new file mode 100644 index 0000000..672e3e8 --- /dev/null +++ b/c/sources/client.c @@ -0,0 +1,96 @@ +#define EZIPC_IMPL +#include "ezipc.h" + +#include "common.h" + + +int main(void) +{ + printf("EZIPC C Client\n"); + + + printf("Connecting..."); + fflush(stdout); + + ezi_conn* conn = ezi_connect(EZIPC_TEST_PATH); + assert(conn); + + printf(" DONE!\n"); + + msg msg_txt = { .type = MSG_TEXT }; + msg msg_exit = { .type = MSG_EXIT }; + + bool running = true; + while(running) + { + char in[1024] = {0}; + printf("send> "); + scanf("%[^\n]%*c", in); + + if(strcmp(in, "exit") != 0) + { + strcpy((char*)msg_txt.data, in); + if(!ezi_send(conn, &msg_txt, sizeof(msg_txt))) + { + printf("Send error, resetting...\n"); + + ezi_disconnect(conn); + conn = ezi_connect(EZIPC_TEST_PATH); + assert(conn); + + continue; + } + } + else + { + if(!ezi_send(conn, &msg_exit, sizeof(msg_exit))) + { + ezi_disconnect(conn); + exit(1); + } + + break; + } + + msg rmsg = {0}; + size_t rsz = sizeof(rmsg); + if(!ezi_recv(conn, &rmsg, &rsz)) + { + printf("Recv error, resetting...\n"); + + ezi_disconnect(conn); + conn = ezi_connect(EZIPC_TEST_PATH); + assert(conn); + + continue; + } + + switch(rmsg.type) + { + case MSG_OK: + { + printf("acknowledged!\n"); + + } break; + + case MSG_EXIT: + { + running = false; + printf("told to exit...\n"); + + } break; + + case MSG_TEXT: + { + printf("received: '%s'\n", (char*)rmsg.data); + + } break; + + default: exit(1); + } + } + + ezi_disconnect(conn); + return 0; +} + |