SFML community forums

Help => Network => Topic started by: Ruckamongus on November 22, 2012, 02:23:11 am

Title: Selector Status and TcpSocket Status Different
Post by: Ruckamongus on November 22, 2012, 02:23:11 am
I've got a few TcpSockets and a TcpListener in a selector. Why does this happen:

if (selector.isReady(client))
{
        // The client has sent some data, we can receive it
        std::cout << "Is ready\n";//Shows
       
        sf::Packet packet;
        int Status = client.receive(packet);
       
        std::cout << "Status: " << Status << '\n';//Displays 1, aka Socket::NotReady
        if (Status == sf::Socket::Done)
        {
                std::cout << "Message recieved!\n"; //Never happens
        }
}
 

Shouldn't these values be the same? I'm using the SocketSelector example in the SFML 2.0 documentation. I am also using the latest git snapshot of SFML. One final thing: both the listener and all TcpSockets are NOT blocking.
Title: Re: Selector Status and TcpSocket Status Different
Post by: Laurent on November 22, 2012, 08:08:00 am
A socket is ready for reading if calling the receive function wouldn't block. So non-blocking sockets are always ready. It doesn't make sense to use a selector with non-blocking sockets.
Title: Re: Selector Status and TcpSocket Status Different
Post by: Ruckamongus on November 22, 2012, 08:20:19 am
Yeah, I suppose that makes sense. I would like to mention though, that using the method from above does not work, but the other version does. I mean:

receive (void *data, std::size_t size, std::size_t &received)


Works properly, whereas

receive (Packet &packet)

does not, with the exact same code. Maybe if you have time to test your example on the documentation (http://www.sfml-dev.org/documentation/2.0/classsf_1_1SocketSelector.php (http://www.sfml-dev.org/documentation/2.0/classsf_1_1SocketSelector.php)) you can see what I mean. the given example does not work with the packet version.