I have got a problem because i can't synchronize sending and receiving data in two separate threads. In the first one i am sending data by:
this->send(0, std::to_string(nr_of_clients - 1));
in the another one i am receiving data by:
sf::Socket::Status tmp_soc;
do
{
tmp_soc = socket.receive(&data, 100, received);
} while (tmp_soc == sf::Socket::Status::NotReady);
std::string output_string(data);
std::cout << "Odebrano: " << output_string << std::endl;
If i send data in the way that i am sure that it will reach it destination just before i am trying to receive it, it is all working well. But there are some situations that i can't be sure when i will be able to send and receive data.
Of course, i have tried with:
sf::TcpSocket socket;
sf::SocketSelector selector;
selector.add(socket);
and
if (selector.isReady(socket))
{
// this socket is ready, you can receive (or accept if it's a listener)
socket.receive(...);
}
but it didn't work.
I would be very thankful if someone could help me in some way, of course i will give best answer mark and so on, so don't worry :) Thank You in advance :)
