Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved] Stop sending  (Read 2259 times)

0 Members and 1 Guest are viewing this topic.

kol

  • Newbie
  • *
  • Posts: 31
    • View Profile
[Solved] Stop sending
« 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;
                */

}
 
« Last Edit: February 13, 2015, 03:09:11 am by kol »

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Stop sending
« Reply #1 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?

kol

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Stop sending
« Reply #2 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?

 :-\

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Stop sending
« Reply #3 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.

kol

  • Newbie
  • *
  • Posts: 31
    • View Profile
Re: Stop sending
« Reply #4 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.