SFML community forums

Help => Network => Topic started by: Soul on May 29, 2014, 05:45:48 pm

Title: receive timeout don't work
Post by: Soul on May 29, 2014, 05:45:48 pm
Hey, i have this code, and i don't know why timeout don't work...
void Server::update()  /// stupid sending packets...
{
    for( std::vector<Client*>::iterator it = clients.begin(); it!= clients.end(); ++it )
    {
        Client &client = **it;
        if (Selector.wait(sf::milliseconds(500)))
        {
            if(Selector.isReady(client.Socket))
            {
                if ( client.Recv(50) )
                {
                 ...
                }
                else                    /// This line never do...
                SendMapInfo();
            }
        }
    }
}

bool Client::Recv(float t)
{
    send.clear();
    recv.clear();
    sf::SocketSelector selector;
    selector.add(Socket);
    if( selector.wait(sf::milliseconds(t)))
    {
        if(Socket.receive(recv)== sf::Socket::Done)
        {
            recv >> family >> action;
            return true;
        }
        else return false;
    }
    else return false;
}