Running two UDP server simultaneously using select()
Hello to everyone,
I'm trying to run two UDP server using the function select().
Here is the code, further information follows below:
Intention is to send messages to the first socket, which works fine.
int port1 = 1234;
int port2 = 1322;
const int buf = 1024;
ConnLessServer testServer1(port1); //first server is opened with given port
ConnLessServer testServer2(port2); //second server is opened with given port
FD_SET(testServer1.getSocket(), &read); //returns the socket filedeskriptor
max_socket_number = *max_element(fd_vector.begin(), fd_vector.end());
ret = select(max_socket_number + 1, &read, NULL, NULL, NULL);
std::cout << std::endl << ret << std::endl;
testServer1.receive(data, size, buf);
fprintf(stdout, "Server 1: %ld %s\n", size, data);
testServer2.receive(data_2, size, buf);
fprintf(stdout, "Server 2: %ld %s\n", size, data_2);
while (0 != strcmp(data_2, "quit"));
The second socket is intented to receive one message, after which the "do-while"-loop should be left.
Problem is, that the second message doesn't seem to be recognized and the message "quit" is ignored. Using a debugger, everything seems to work fine, "quit" is received and the loop is left.
In case, more information is needed, I can post some code of the member functions, I wrote myself (e.g. for the class ConnLessServer).