SFML community forums

Help => Network => Topic started by: kol on February 09, 2015, 10:14:26 pm

Title: [Solved] Stop sending
Post by: kol on February 09, 2015, 10:14:26 pm
In the first all is well, but in the second it stops sending. Must I always send and receive, even if it is an empty socket?

bool client(){
                const char out[] = "Hi, I'm a client";
                if (socket.send(out, sizeof(out), server, PORT) != sf::Socket::Done)
                return false;


                char in[128];
                std::size_t received;
                sf::IpAddress sender;
                unsigned short senderPort;
                if (socket.receive(in, sizeof(in)  , received, sender, senderPort) != sf::Socket::Done)
                return false;

        }

void server(){
                char in[128];
                std::size_t received;
                sf::IpAddress sender;
                unsigned short senderPort;
                if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
                return false;
       
                const char out[] = "";
                if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
                return false;
}
 

Second:

bool client(){
                const char out[] = "Hi, I'm a client";
                if (socket.send(out, sizeof(out), server, PORT) != sf::Socket::Done)
                return false;

                char in[128];
                std::size_t received;
                sf::IpAddress sender;
                unsigned short senderPort;
                if (socket.receive(in, sizeof(in)  , received, sender, senderPort) != sf::Socket::Done)
                return false;

        }

void server(){
                char in[128];
                std::size_t received;
                sf::IpAddress sender;
                unsigned short senderPort;
                if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done)
                return false;
                /*     
                const char out[] = "";
                if (socket.send(out, sizeof(out), sender, senderPort) != sf::Socket::Done)
                return false;
                */

}
 
Title: Re: Stop sending
Post by: Gambit on February 09, 2015, 10:57:41 pm
Can you explain a little more about your situtation, the problem you are having and the desired result as opposed to just posting code and letting everyone else try figure out what the problem is?

What is an empty socket? Do you mean a socket that is not connected or did you confuse socket with packet?
Title: Re: Stop sending
Post by: kol on February 10, 2015, 03:28:22 am
So my friend. It simply stops sending. At first, he is sending and receiving infinitely. However, in the second server stops receiving. My question was: I would have to send and receive even if it was empty packages to continue endlessly?

 :-\
Title: Re: Stop sending
Post by: G. on February 10, 2015, 03:42:14 am
I'm not sure what you want. But you probably don't want to put an ; at the end of an if.
Quote
if (socket.receive(in, sizeof(in), received, sender, senderPort) != sf::Socket::Done);
        return false;
return false; will always be executed, whether your if is true or false.
Title: Re: Stop sending
Post by: kol on February 13, 2015, 03:08:25 am
I'm sorry, only now understand how it worked the "setBlocking". I'am very stupid. Many apologies.