SFML community forums

Help => Network => Topic started by: omicronns on December 18, 2014, 01:58:37 am

Title: [TcpSocket] Receive does not block
Post by: omicronns on December 18, 2014, 01:58:37 am
Here is a minimal example of my problem:

int main(int argc, char **argv) {
    sf::TcpListener lst;
    lst.listen(10000);
    sf::TcpSocket sck;
    lst.accept(sck);

    while(true) {
        char data[10];
        unsigned long len;
        sck.receive(data, 10UL, len);
        sck.send(data, len);
    }
}
 

Following program after receiving a packet starts to put following message to stdout: "Cannot send data over the network (no data to send)", however i can receive first echo reply as a source of this packet. As I found, it is a message prompted by send function when called with len=0. But shouldn't receive method wait until it receives some portion of data in default blocking mode?

If i do something like that it's working as desired:

int main(int argc, char **argv) {
    sf::TcpListener lst;
    lst.listen(10000);
    sf::TcpSocket sck;
    lst.accept(sck);

    while(true) {
        char data[10];
        unsigned long len;
        do {
            sck.receive(data, 10UL, len);
        } while(len == 0);
        sck.send(data, len);
    }
}
 

Am I misunderstanding something?

I'm running on Ubuntu 14.10 using [libsfml-network2 2.1+dfsg2-1] library, code compiled with [g++ 4:4.9.1-4ubuntu2]

Thanks for your help in advance