#include #include #include #include #include int main(){ int fd = socket(AF_INET, SOCK_STREAM, 0); // isoptera: 74.118.22.194 = 0x4a7618c2 struct sockaddr_in addr = {AF_INET, htons(5100), {htonl(0x4a7616c2)}}; printf("Connecting to: %s\n", inet_ntoa(addr.sin_addr)); if(connect(fd, (struct sockaddr*)&addr, sizeof(addr))){ perror("connect: "); return 1; } char type; int32_t weight; for(;;){ printf("Enter the type (N or Q): "); retry: scanf("%c", &type); if(type == '\n') goto retry; if(type == 'N'){ printf("Enter the weight in grams: "); scanf("%d", &weight); write(fd, &type, 1); write(fd, &weight, 4); read(fd, &type, 1); if(type != 'A') printf("Something went wrong\n"); } else if(type == 'Q'){ write(fd, &type, 1); read(fd, &type, 1); if(type != 'S') printf("Something went wrong\n"); int32_t results[2]; read(fd, &results, 8); printf("Squirrels: %d\nAverage Weight: %d\n", results[0], results[1]); } else { printf("Unknown type \"%c\"\n", type); break; } } close(fd); return 0; }