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

Author Topic: recive data in loop  (Read 2021 times)

0 Members and 1 Guest are viewing this topic.

CreaM

  • Newbie
  • *
  • Posts: 36
    • View Profile
recive data in loop
« on: April 30, 2014, 05:12:25 pm »
Hi, how can i receive data in same loop, and in case no data comes in three secs (for example) the loop continues

- i could sand data at,,every start of loop,, just sometimes ,,fill them,, but isnt another easier way?
(tcp cockets)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: recive data in loop
« Reply #1 on: April 30, 2014, 06:13:36 pm »
http://www.sfml-dev.org/tutorials/2.1/network-socket.php

Quote
As a bonus, the timeout capability of Selector::wait allows to implement a receive-with-timeout function, which is not directly available in the socket classes, very easily:

sf::Socket::Status receiveWithTimeout(sf::TcpSocket& socket, sf::Packet& packet, sf::Time timeout)
{
    sf::SocketSelector selector;
    selector.add(socket);
    if (selector.wait(timeout))
        return socket.receive(packet);
    else
        return sf::Socket::NotReady;
}
Laurent Gomila - SFML developer

 

anything