#include #include #include #include #include #include char *advice[] = { "Take the hard path\r\n", "Don't please others\r\n", "Ignore others opinions\r\n", "Keep moving forward\r\n", }; int main(void) { int sock_d = socket(PF_INET, SOCK_STREAM, 0); struct sockaddr_in name; name.sin_family = PF_INET; name.sin_port = (in_port_t)htons(30000); name.sin_addr.s_addr = htonl(INADDR_ANY); bind(sock_d, (struct sockaddr *)&name, sizeof(name)); listen(sock_d, 10); puts("Waiting connection...\n"); while (1) { struct sockaddr_storage client_addr; unsigned int addr_size = sizeof(client_addr); int client_sock = accept(sock_d, (struct sockaddr *)&client_addr, &addr_size); char *msg = advice[rand() % 4]; send(client_sock, msg, strlen(msg), 0); close(client_sock); } return 0; }