C++ recvfrom timeout
问题 I need to implement following behavior: when server starts, it should check for existing servers using broadcast. Then it waits for answer. But, how to set any timeout for waiting? int optval = 1; char buff[BUFF_SIZE]; SOCKADDR_IN addr; int length = sizeof(addr); if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char*)&optval, sizeof(optval)) == SOCKET_ERROR) throw(errors::SETSOCKOPT); addr->sin_family = AF_INET; addr->sin_port = htons(this->serverPort); addr->sin_addr.s_addr = INADDR_ANY; sendto