#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; }