// main.c #include #include #include #include "world.h" #include "error.h" #include "sock.h" int main(void) { enum error_t err = ERR_OK; int sock; err = sock_init(&sock); if (err) goto handle_error; char ibuf[1024] = { 0 }; char obuf[1024] = { 0 }; // TODO: I skipped out on most error handling here read(sock, ibuf, 1024); struct json_error_t json_err; struct json_t *json = json_loads(ibuf, 0, &json_err); struct world_t world = { 0 }; world_deserialise(&world, json); printf("CLIENT: (%zu %zu)\n", world.height, world.width); struct json_t *new_json; world_serialise(&world, &new_json); json_dumpb(new_json, obuf, 1024, 0); write(sock, obuf, 1024); close(sock); return ERR_OK; handle_error: printf("ERROR: %s\n", ERROR_STRS[err]); return err; }