0

I have two detached threads in server: for receiving and sending data. All work fine, until setting client's sending frequency to 16 ms (< ~200 ms). In this state one thread always wins the race and answers to only one client with ~1 us ping. What I need to do to send and receive data in separate threads with two (or one) UDP sockets?

Part of server's code:

void Server::receive() {
    while(true) {
        if (recvfrom(getReceiver()->getSocketDesc(), buffer, getBufferLength(), 0, (struct sockaddr *) &currentClient, getReceiver()->getLength()) < 0) {
        // add message to client's own thread-safe buffer
        }
    }
}

void Server::send() {
    while(true) {
        // get message from thread-safe general buffer after processing
        // dequeue one
        if (message != nullptr)
            sendto(getDispatcher()->getSocketDesc(), "hi", 2, 0, message->_addr, *getDispatcher()->getLength());
    }
}

0 Answers0