0

my question is very short. I have an array of sockets and from each socket I have to accept a packet. But if a socket is sending pockets too slowly, then the entire execution process is delayed. How can I skip it, if at the time of reading its pocket, it has not yet been sent. I see it somehow like this:

if(Clients[i].socket.isReady()){
    Clients[i].socket.recive(data)
}
else{
 ...
}
  • 2
    The answer is that you should use threads, but multithreading in C++ is much too complex of a topic for a single StackOverflow answer. You should refer to your [C++ Textbook](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and read about multithreading, parallelism/concurrency, and thread synchronization and communication methods. – alter_igel Mar 02 '21 at 17:56
  • Or if you don't want to go the multithreading route you might want to have a look at [`boost.asio`](https://www.boost.org/doc/libs/1_75_0/doc/html/boost_asio.html). – G.M. Mar 02 '21 at 17:59
  • Or you could call `setBlocking(false)` on the socket, then the receive function will return `sf::Socket::Status::NotReady` if it is not ready. – Lily Mar 02 '21 at 21:34

0 Answers0